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.

(cherry picked from commit 032da815fa)
(added status entry)
This commit is contained in:
Scott Kostyshak 2015-03-31 12:53:23 -04:00
parent 3cf887f08e
commit cecd327755
2 changed files with 42 additions and 28 deletions

View File

@ -617,12 +617,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; break;
case LFUN_CHAR_FORWARD: case LFUN_CHAR_FORWARD:
case LFUN_CHAR_FORWARD_SELECT: case LFUN_CHAR_FORWARD_SELECT: {
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur); //LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT); 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() if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD); cmd = FuncRequest(LFUN_FINISHED_FORWARD);
@ -642,14 +643,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
break; break;
}
case LFUN_CHAR_BACKWARD: case LFUN_CHAR_BACKWARD:
case LFUN_CHAR_BACKWARD_SELECT: case LFUN_CHAR_BACKWARD_SELECT: {
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl; //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT); 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() if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD); cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
@ -669,13 +672,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
break; break;
}
case LFUN_CHAR_LEFT: case LFUN_CHAR_LEFT:
case LFUN_CHAR_LEFT_SELECT: case LFUN_CHAR_LEFT_SELECT:
if (lyxrc.visual_cursor) { if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT); needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
needsUpdate |= cursorVisLeft(cur); bool const cur_moved = cursorVisLeft(cur);
if (!needsUpdate && oldTopSlice == cur.top() needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
@ -697,8 +702,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CHAR_RIGHT_SELECT: case LFUN_CHAR_RIGHT_SELECT:
if (lyxrc.visual_cursor) { if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT); needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
needsUpdate |= cursorVisRight(cur); bool const cur_moved = cursorVisRight(cur);
if (!needsUpdate && oldTopSlice == cur.top() needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
@ -808,8 +814,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_WORD_RIGHT_SELECT: case LFUN_WORD_RIGHT_SELECT:
if (lyxrc.visual_cursor) { if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT); needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
needsUpdate |= cursorVisRightOneWord(cur); bool const cur_moved = cursorVisRightOneWord(cur);
if (!needsUpdate && oldTopSlice == cur.top() needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
@ -828,11 +835,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; break;
case LFUN_WORD_FORWARD: case LFUN_WORD_FORWARD:
case LFUN_WORD_FORWARD_SELECT: case LFUN_WORD_FORWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == 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() if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD); cmd = FuncRequest(LFUN_FINISHED_FORWARD);
@ -852,13 +860,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
break; break;
}
case LFUN_WORD_LEFT: case LFUN_WORD_LEFT:
case LFUN_WORD_LEFT_SELECT: case LFUN_WORD_LEFT_SELECT:
if (lyxrc.visual_cursor) { if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT); needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
needsUpdate |= cursorVisLeftOneWord(cur); bool const cur_moved = cursorVisLeftOneWord(cur);
if (!needsUpdate && oldTopSlice == cur.top() needsUpdate |= cur_moved;
if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
@ -877,11 +887,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; break;
case LFUN_WORD_BACKWARD: case LFUN_WORD_BACKWARD:
case LFUN_WORD_BACKWARD_SELECT: case LFUN_WORD_BACKWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == 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() if (!cur_moved && oldTopSlice == cur.top()
&& cur.boundary() == oldBoundary) { && cur.boundary() == oldBoundary) {
cur.undispatched(); cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD); cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
@ -902,6 +913,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
break; break;
}
case LFUN_WORD_SELECT: { case LFUN_WORD_SELECT: {
selectWord(cur, WHOLE_WORD); selectWord(cur, WHOLE_WORD);

View File

@ -161,6 +161,8 @@ What's new
- Allow cursor to exit table when in selection mode (bug 9291). - Allow cursor to exit table when in selection mode (bug 9291).
- Fix selection at borders of insets (bug 9487).
* INTERNALS * INTERNALS