]> git.lyx.org Git - features.git/commitdiff
Improve instant search
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 15 Feb 2021 13:12:07 +0000 (14:12 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 15 Feb 2021 13:12:07 +0000 (14:12 +0100)
src/BufferView.cpp
src/frontends/qt/GuiSearch.cpp
src/frontends/qt/GuiSpellchecker.cpp
src/lyxfind.cpp
src/lyxfind.h

index 81b76916e1979a53a456aaf4959de351ce8aae82..534e3bc2d96f7ad9fcea4c0cff4c15d68ae109d4 100644 (file)
@@ -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);
index 6c72ab86f9d0e1e9c5ebd26fb12cdb8f7fe73c04..1658804cd1d0930c87431649cf0472b809c21a72 100644 (file)
@@ -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));
 }
index 40ad72c5577d184ecc11a11340ad7929b284fa34..d36f5627c91d64b7c02a5480bf46833d50773a30 100644 (file)
@@ -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();
index 8c671414eb41ce79d59fbb02aa1ce3aed938333a..8487c013265cea16c5601b93ad748d03fc0f79f5 100644 (file)
@@ -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);
 }
 
 
index b6e9ec911364a571a334eee133dbee640d074fdf..484754944c991bb5e30ab635d02d604c93032ee8 100644 (file)
@@ -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.