Avoid crash when extending word selection

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.
This commit is contained in:
Jean-Marc Lasgouttes 2022-05-05 10:44:45 +02:00
parent 9f30de3c5d
commit 809a063358

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