From: Scott Kostyshak Date: Tue, 31 Mar 2015 16:53:23 +0000 (-0400) Subject: Fix selection at borders of insets (#9487) X-Git-Tag: 2.2.0alpha1~1058 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=032da815fabf5478b447cc5b093ca2a44d72ae2f;p=lyx.git 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. --- diff --git a/src/Text3.cpp b/src/Text3.cpp index 517998bef6..af15c313f2 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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);