Word selection on mouse motion

Partial fix for bug #9160.
This commit is contained in:
Daniel Ramoeller 2022-05-16 03:57:03 +02:00 committed by Jean-Marc Lasgouttes
parent 5f8959d40e
commit 2b493ff70f
4 changed files with 23 additions and 12 deletions

View 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());

View 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);

View 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) {

View 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;