From 2b493ff70f0ccc753125409096fa59563bfe13b8 Mon Sep 17 00:00:00 2001 From: Daniel Ramoeller Date: Mon, 16 May 2022 03:57:03 +0200 Subject: [PATCH] Word selection on mouse motion Partial fix for bug #9160. --- src/Text.cpp | 14 ++++++++++++++ src/Text.h | 2 ++ src/Text3.cpp | 15 ++++----------- src/insets/InsetTabular.cpp | 4 +++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Text.cpp b/src/Text.cpp index e379337ee8..7857e5e06c 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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()); diff --git a/src/Text.h b/src/Text.h index 64cbb834c2..9736981941 100644 --- a/src/Text.h +++ b/src/Text.h @@ -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); diff --git a/src/Text3.cpp b/src/Text3.cpp index 8143f39daa..5bfde06679 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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) { diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 749c244263..d1f789580a 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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; -- 2.39.5