]> git.lyx.org Git - features.git/commitdiff
Word selection on mouse motion
authorDaniel Ramoeller <d.lyx@web.de>
Mon, 16 May 2022 01:57:03 +0000 (03:57 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 17 May 2022 16:45:31 +0000 (18:45 +0200)
Partial fix for bug #9160.

src/Text.cpp
src/Text.h
src/Text3.cpp
src/insets/InsetTabular.cpp

index e379337ee89a527bee072b38e20491a41d41e4f2..7857e5e06c9dc00cd6a107102031bd60041b8676 100644 (file)
@@ -1369,6 +1369,20 @@ void Text::selectWord(Cursor & cur, word_location loc)
 }
 
 
+void Text::expandWordSel(Cursor & cur)
+{
+       // get selection of word around cur
+       Cursor c = cur;
+       c.selection(false);
+       c.text()->selectWord(c, WHOLE_WORD);
+       // use the correct word boundary, depending on selection direction
+       if (cur.top() > cur.normalAnchor())
+               cur.pos() = c.selEnd().pos();
+       else
+               cur.pos() = c.selBegin().pos();
+}
+
+
 void Text::selectAll(Cursor & cur)
 {
        LBUFERR(this == cur.text());
index 64cbb834c21bbf1ffc032920a1c6d65fbb349263..9736981941b2b7d99c337ef195d85f512b344dcc 100644 (file)
@@ -171,6 +171,8 @@ public:
        void getWord(CursorSlice & from, CursorSlice & to, word_location const) const;
        /// just selects the word the cursor is in
        void selectWord(Cursor & cur, word_location loc);
+       /// expands the selection to the word the cursor is in
+       void expandWordSel(Cursor & cur);
        /// select all text
        void selectAll(Cursor & cur);
 
index 8143f39daaad1f17397df3f20d9649214b7420c8..5bfde0667958643cfd6c8831e239eeac65dac217 100644 (file)
@@ -1875,17 +1875,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
                                cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
                        // FIXME: move this to mouseSetCursor?
-                       if (bvcur.wordSelection() && bvcur.inTexted()) {
-                               // select word around new position
-                               Cursor c = bvcur;
-                               c.selection(false);
-                               c.text()->selectWord(c, WHOLE_WORD);
-                               // use the correct word boundary, depending on selection direction
-                               if (bvcur.top() > bvcur.normalAnchor())
-                                       bvcur.pos() = c.selEnd().pos();
-                               else
-                                       bvcur.pos() = c.selBegin().pos();
-                       }
+                       if (bvcur.wordSelection() && bvcur.inTexted())
+                               expandWordSel(bvcur);
                        break;
 
                case mouse_button::button2:
@@ -1953,6 +1944,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // We continue with our existing selection or start a new one, so don't
                // reset the anchor.
                bvcur.setCursor(cur);
+               if (bvcur.wordSelection() && bvcur.inTexted())
+                       expandWordSel(bvcur);
                bvcur.selection(true);
                bvcur.setCurrentFont();
                if (cur.top() == old) {
index 749c244263279f4d15404b2a1c457990f9447a34..d1f789580a8827040d9fd8d583084837941c8a52 100644 (file)
@@ -5043,7 +5043,9 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        if (bvcur.selIsMultiCell()) {
                                bvcur.pit() = bvcur.lastpit();
                                bvcur.pos() = bvcur.lastpos();
-                       }
+                       } else
+                               // Let InsetTableCell do it
+                               cell(cur.idx())->dispatch(cur, cmd);
                }
                break;