Fix selection at borders of insets (#9487)

When at the last position in an inset, selecting to the right
should select the entire inset. This only worked if there was
already a selection (i.e. the selection was started not at the
boundary).

The behavior of this bug was changed by commit 73a7bf9d.  Before
that commit, if at the last position of an inset you select to
the right, nothing is selected but the selection is set. If you
select once more to the right, because the selection is set the
needsUpdate condition is satisfied so the whole inset is selected.

Note that everything here applies also to "first position of an
inset" and selecting to the left. By "selecting", I am referring
to LFUN_{CHAR,WORD}_{FORWARD,BACKWARD}_SELECT.
This commit is contained in:
Scott Kostyshak 2015-03-31 12:53:23 -04:00
parent 26f0ee1eb3
commit 032da815fa

View File

@ -605,13 +605,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_CHAR_FORWARD:
case LFUN_CHAR_FORWARD_SELECT:
case LFUN_CHAR_FORWARD_SELECT: {
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
needsUpdate |= cursorForward(cur);
bool const cur_moved = cursorForward(cur);
needsUpdate |= cur_moved;
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
@ -630,15 +631,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
break;
}
case LFUN_CHAR_BACKWARD:
case LFUN_CHAR_BACKWARD_SELECT:
case LFUN_CHAR_BACKWARD_SELECT: {
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
needsUpdate |= cursorBackward(cur);
bool const cur_moved = cursorBackward(cur);
needsUpdate |= cur_moved;
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
@ -657,14 +660,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
break;
}
case LFUN_CHAR_LEFT:
case LFUN_CHAR_LEFT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
needsUpdate |= cursorVisLeft(cur);
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
bool const cur_moved = cursorVisLeft(cur);
needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
@ -685,9 +690,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CHAR_RIGHT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
needsUpdate |= cursorVisRight(cur);
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
bool const cur_moved = cursorVisRight(cur);
needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
@ -796,9 +802,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_WORD_RIGHT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
needsUpdate |= cursorVisRightOneWord(cur);
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
bool const cur_moved = cursorVisRightOneWord(cur);
needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
@ -816,12 +823,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_WORD_FORWARD:
case LFUN_WORD_FORWARD_SELECT:
case LFUN_WORD_FORWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
needsUpdate |= cursorForwardOneWord(cur);
bool const cur_moved = cursorForwardOneWord(cur);
needsUpdate |= cur_moved;
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
@ -840,14 +848,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
break;
}
case LFUN_WORD_LEFT:
case LFUN_WORD_LEFT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
needsUpdate |= cursorVisLeftOneWord(cur);
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
bool const cur_moved = cursorVisLeftOneWord(cur);
needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
@ -865,12 +875,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_WORD_BACKWARD:
case LFUN_WORD_BACKWARD_SELECT:
case LFUN_WORD_BACKWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
needsUpdate |= cursorBackwardOneWord(cur);
bool const cur_moved = cursorBackwardOneWord(cur);
needsUpdate |= cur_moved;
if (!needsUpdate && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
@ -890,6 +901,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
}
break;
}
case LFUN_WORD_SELECT: {
selectWord(cur, WHOLE_WORD);