]> git.lyx.org Git - features.git/commitdiff
Avoid crash when extending word selection
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 5 May 2022 08:44:45 +0000 (10:44 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 5 May 2022 09:13:29 +0000 (11:13 +0200)
This happens when the cursor goes into a deeper inset, since
selectWord() was called on the wrong Text object.

Additionally, fix the new word selection when cursor goes before
existing selection.

Fixes bug #12529.

src/Text3.cpp

index 185008b7255197995b61405a148aa2f4bf27b251..f871bb31d157c1b1a91371428be779b2774ebb21 100644 (file)
@@ -1874,8 +1874,18 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                bvcur.resetAnchor();
                        if (!bv->mouseSetCursor(cur, cmd.modifier() == ShiftModifier))
                                cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
-                       if (bvcur.wordSelection())
-                               selectWord(bvcur, WHOLE_WORD);
+                       // 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();
+                       }
                        break;
 
                case mouse_button::button2: