[LyX/master] Improve instant search

Juergen Spitzmueller spitz at lyx.org
Mon Feb 15 13:09:00 UTC 2021


commit 958213ee5211f3b81597c56e49c453c82a340ad1
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Feb 15 14:12:07 2021 +0100

    Improve instant search
---
 src/BufferView.cpp                   |    7 ++++-
 src/frontends/qt/GuiSearch.cpp       |    9 +++----
 src/frontends/qt/GuiSpellchecker.cpp |    2 +-
 src/lyxfind.cpp                      |   38 ++++++++++++++++++++++-----------
 src/lyxfind.h                        |    8 ++++--
 5 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 81b7691..534e3bc 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -459,7 +459,9 @@ void BufferView::setSearchRequestCache(docstring const & text)
 	bool matchword;
 	bool forward;
 	bool wrap;
-	docstring const search = string2find(text, casesensitive, matchword, forward, wrap);
+	bool instant;
+	docstring const search = string2find(text, casesensitive, matchword,
+					     forward, wrap, instant);
 	theClipboard().setFindBuffer(search);
 }
 
@@ -1645,7 +1647,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			break;
 
 		docstring const data =
-			find2string(searched_string, false, false, act == LFUN_WORD_FIND_FORWARD, false);
+			find2string(searched_string, false, false,
+				    act == LFUN_WORD_FIND_FORWARD, false, false);
 		bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
 		if (found)
 			dr.screenUpdate(Update::Force | Update::FitCursor);
diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index 6c72ab8..1658804 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -230,13 +230,12 @@ void GuiSearchWidget::replaceallClicked()
 
 
 void GuiSearchWidget::find(docstring const & search, bool casesensitive,
-			 bool matchword, bool forward, bool instant, bool wrap)
+			 bool matchword, bool forward, bool instant,
+			 bool wrap)
 {
 	docstring const sdata =
-		find2string(search, casesensitive, matchword, forward, wrap);
-	if (instant)
-		// re-query current match
-		dispatch(FuncRequest(LFUN_WORD_BACKWARD));
+		find2string(search, casesensitive, matchword,
+			    forward, wrap, instant);
 
 	dispatch(FuncRequest(LFUN_WORD_FIND, sdata));
 }
diff --git a/src/frontends/qt/GuiSpellchecker.cpp b/src/frontends/qt/GuiSpellchecker.cpp
index 40ad72c..d36f562 100644
--- a/src/frontends/qt/GuiSpellchecker.cpp
+++ b/src/frontends/qt/GuiSpellchecker.cpp
@@ -467,7 +467,7 @@ void SpellcheckerWidget::on_findNextPB_clicked()
 		return;
 	docstring const textfield = qstring_to_ucs4(d->ui.wordED->text());
 	docstring const datastring = find2string(textfield,
-				true, true, true, false);
+				true, true, true, false, false);
 	LYXERR(Debug::GUI, "Spellchecker: find next (" << textfield << ")");
 	dispatch(FuncRequest(LFUN_WORD_FIND, datastring));
 	d->canCheck();
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 8c67141..8487c01 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -267,14 +267,15 @@ bool searchAllowed(docstring const & str)
 
 bool findOne(BufferView * bv, docstring const & searchstr,
 	     bool case_sens, bool whole, bool forward,
-	     bool find_del, bool check_wrap, bool auto_wrap)
+	     bool find_del, bool check_wrap, bool auto_wrap,
+	     bool instant)
 {
 	if (!searchAllowed(searchstr))
 		return false;
 
 	DocIterator cur = forward
-		? bv->cursor().selectionEnd()
-		: bv->cursor().selectionBegin();
+		? (instant ? bv->cursor().selectionBegin() : bv->cursor().selectionEnd())
+		: (instant ? bv->cursor().selectionEnd() : bv->cursor().selectionBegin());
 
 	MatchString const match(searchstr, case_sens, whole);
 
@@ -307,7 +308,8 @@ bool findOne(BufferView * bv, docstring const & searchstr,
 				bv->cursor().backwardPos();
 			}
 			bv->clearSelection();
-			if (findOne(bv, searchstr, case_sens, whole, forward, find_del, false, false))
+			if (findOne(bv, searchstr, case_sens, whole, forward,
+				    find_del, false, false, false))
 				return true;
 		}
 		bv->cursor().setCursor(cur_orig);
@@ -390,7 +392,8 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
 	if (!cur.selection()) {
 		// no selection, non-empty search string: find it
 		if (!searchstr.empty()) {
-			bool const found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext, wrap);
+			bool const found = findOne(bv, searchstr, case_sens, whole,
+						   forward, true, findnext, wrap, false);
 			return make_pair(found, 0);
 		}
 		// empty search string
@@ -419,7 +422,8 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
 	// no selection or current selection is not search word:
 	// just find the search word
 	if (!have_selection || !match) {
-		bool const found = findOne(bv, searchstr, case_sens, whole, forward, true, findnext, wrap);
+		bool const found = findOne(bv, searchstr, case_sens, whole, forward,
+					   true, findnext, wrap, false);
 		return make_pair(found, 0);
 	}
 
@@ -435,7 +439,8 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
 		        cur.pos() = cur.lastpos());
 	}
 	if (findnext)
-		findOne(bv, searchstr, case_sens, whole, forward, false, findnext, wrap);
+		findOne(bv, searchstr, case_sens, whole,
+			forward, false, findnext, wrap, false);
 
 	return make_pair(true, 1);
 }
@@ -445,14 +450,15 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
 
 docstring const find2string(docstring const & search,
 			    bool casesensitive, bool matchword,
-			    bool forward, bool wrap)
+			    bool forward, bool wrap, bool instant)
 {
 	odocstringstream ss;
 	ss << search << '\n'
 	   << int(casesensitive) << ' '
 	   << int(matchword) << ' '
 	   << int(forward) << ' '
-	   << int(wrap);
+	   << int(wrap) << ' '
+	   << int(instant);
 	return ss.str();
 }
 
@@ -479,7 +485,8 @@ docstring const string2find(docstring const & argument,
 			      bool &casesensitive,
 			      bool &matchword,
 			      bool &forward,
-			      bool &wrap)
+			      bool &wrap,
+			      bool &instant)
 {
 	// data is of the form
 	// "<search>
@@ -490,7 +497,8 @@ docstring const string2find(docstring const & argument,
 	casesensitive = parse_bool(howto);
 	matchword     = parse_bool(howto);
 	forward       = parse_bool(howto, true);
-	wrap          = parse_bool(howto, true);
+	wrap          = parse_bool(howto);
+	instant       = parse_bool(howto);
 
 	return search;
 }
@@ -506,9 +514,13 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev)
 	bool matchword;
 	bool forward;
 	bool wrap;
-	docstring search = string2find(ev.argument(), casesensitive, matchword, forward, wrap);
+	bool instant;
+	
+	docstring search = string2find(ev.argument(), casesensitive,
+				       matchword, forward, wrap, instant);
 
-	return findOne(bv, search, casesensitive, matchword, forward, false, true, wrap);
+	return findOne(bv, search, casesensitive, matchword, forward,
+		       false, true, wrap, instant);
 }
 
 
diff --git a/src/lyxfind.h b/src/lyxfind.h
index b6e9ec9..4847549 100644
--- a/src/lyxfind.h
+++ b/src/lyxfind.h
@@ -35,7 +35,8 @@ docstring const string2find(docstring const & argument,
 			      bool &casesensitive,
 			      bool &matchword,
 			      bool &forward,
-			      bool &wrap);
+			      bool &wrap,
+			      bool &instant);
 
 /** Encode the parameters needed to find \c search as a string
  *  that can be dispatched to the LyX core in a FuncRequest wrapper.
@@ -44,7 +45,8 @@ docstring const find2string(docstring const & search,
 			      bool casesensitive,
 			      bool matchword,
 			      bool forward,
-			      bool wrap);
+			      bool wrap,
+			      bool instant);
 
 /** Encode the parameters needed to replace \c search with \c replace
  *  as a string that can be dispatched to the LyX core in a FuncRequest
@@ -69,7 +71,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev);
 bool findOne(BufferView * bv, docstring const & searchstr,
 	     bool case_sens, bool whole, bool forward,
 	     bool find_del = true, bool check_wrap = false,
-	     bool auto_wrap = false);
+	     bool auto_wrap = false, bool instant = false);
 
 /** Parse the string encoding of the replace request that is found in
  *  \c ev.argument and act on it.


More information about the lyx-cvs mailing list