]> git.lyx.org Git - features.git/commitdiff
Factor out shared method
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 31 Mar 2024 10:40:27 +0000 (12:40 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 31 Mar 2024 10:40:27 +0000 (12:40 +0200)
Amends babb5b007bd

src/BufferView.cpp
src/BufferView.h
src/frontends/qt/GuiSpellchecker.cpp
src/lyxfind.cpp

index ad534eae2842500319bc7b796d24c59157307ea5..39fffed68eac2861adf80a2bd7f7becf70aecf92 100644 (file)
@@ -2993,6 +2993,25 @@ void BufferView::putSelectionAt(DocIterator const & cur,
 }
 
 
+void BufferView::setSelection(DocIterator const & from,
+                             DocIterator const & to)
+{
+       if (from.pit() != to.pit()) {
+               // there are multiple paragraphs in selection
+               cursor().setCursor(from);
+               cursor().clearSelection();
+               cursor().selection(true);
+               cursor().setCursor(to);
+               cursor().selection(true);
+       } else {
+               // only single paragraph
+               int const size = to.pos() - from.pos();
+               putSelectionAt(from, size, false);
+       }
+       processUpdateFlags(Update::Force | Update::FitCursor);
+}
+
+
 bool BufferView::selectIfEmpty(DocIterator & cur)
 {
        if ((cur.inTexted() && !cur.paragraph().empty())
index d239fdd3607b2c1d86081a99e70f9655e7f8ba48..b46ade3df535a1dc8e73e9269317d92d2928542b 100644 (file)
@@ -302,6 +302,9 @@ public:
         */
        void putSelectionAt(DocIterator const & cur,
                int length, bool backwards);
+       /// set a selection between \p from and \p to
+       void setSelection(DocIterator const & from,
+                        DocIterator const & to);
 
        /// selects the item at cursor if its paragraph is empty.
        bool selectIfEmpty(DocIterator & cur);
index d58f435b10ad84ae95cb75e75aa0eb934fd2bc86..66952eb7dc1a413c793ba813c6b787dc1f760b70 100644 (file)
@@ -72,8 +72,6 @@ struct SpellcheckerWidget::Private
        void check();
        /// close the spell checker dialog
        void hide() const;
-       /// make/restore a selection between from and to
-       void setSelection(DocIterator const & from, DocIterator const & to) const;
        /// if no selection was checked:
        /// ask the user if the check should start over
        bool continueFromBeginning();
@@ -339,7 +337,7 @@ void SpellcheckerWidget::Private::hide() const
        if (isCurrentBuffer(bvcur)) {
                if (!begin_.empty() && !end_.empty()) {
                        // restore previous selection
-                       setSelection(begin_, end_);
+                       bv->setSelection(begin_, end_);
                } else {
                        // restore cursor position
                        bvcur.setCursor(start_);
@@ -349,29 +347,6 @@ void SpellcheckerWidget::Private::hide() const
        }
 }
 
-void SpellcheckerWidget::Private::setSelection(
-       DocIterator const & from, DocIterator const & to) const
-{
-       BufferView * bv = gv_->documentBufferView();
-       DocIterator end = to;
-
-       if (from.pit() != end.pit()) {
-               // there are multiple paragraphs in selection
-               Cursor & bvcur = bv->cursor();
-               bvcur.setCursor(from);
-               bvcur.clearSelection();
-               bvcur.selection(true);
-               bvcur.setCursor(end);
-               bvcur.selection(true);
-       } else {
-               // FIXME LFUN
-               // If we used a LFUN, dispatch would do all of this for us
-               int const size = end.pos() - from.pos();
-               bv->putSelectionAt(from, size, false);
-       }
-       bv->processUpdateFlags(Update::Force | Update::FitCursor);
-}
-
 void SpellcheckerWidget::Private::forward()
 {
        DocIterator const from = cursor();
@@ -632,7 +607,7 @@ void SpellcheckerWidget::Private::check()
                return;
        setLanguage(word_lang.lang());
        // mark misspelled word
-       setSelection(from, to);
+       bv->setSelection(from, to);
        // enable relevant widgets
        updateView();
 }
index 6281b82abc8c143c2ebb7dd4bd5a561c8761028b..6e3b324bfa66be867f2bee4d4292bfd6b2ee3422 100644 (file)
@@ -281,27 +281,6 @@ bool searchAllowed(docstring const & str)
        return true;
 }
 
-void setSelection(BufferView * bv, DocIterator const & from, DocIterator const & to)
-{
-       DocIterator end = to;
-
-       if (from.pit() != end.pit()) {
-               // there are multiple paragraphs in selection
-               Cursor & bvcur = bv->cursor();
-               bvcur.setCursor(from);
-               bvcur.clearSelection();
-               bvcur.selection(true);
-               bvcur.setCursor(end);
-               bvcur.selection(true);
-       } else {
-               // FIXME LFUN
-               // If we used a LFUN, dispatch would do all of this for us
-               int const size = end.pos() - from.pos();
-               bv->putSelectionAt(from, size, false);
-       }
-       bv->processUpdateFlags(Update::Force | Update::FitCursor);
-}
-
 } // namespace
 
 
@@ -408,7 +387,7 @@ bool findOne(BufferView * bv, docstring const & searchstr,
                // restore original selection
                if (had_selection) {
                        bv->cursor().resetAnchor();
-                       setSelection(bv, startcur, endcur);
+                       bv->setSelection(startcur, endcur);
                }
                return false;
        }
@@ -485,7 +464,7 @@ int replaceAll(BufferView * bv,
        if (had_selection) {
                endcur.fixIfBroken();
                bv->cursor().resetAnchor();
-               setSelection(bv, startcur, endcur);
+               bv->setSelection(startcur, endcur);
        }
 
        return num;