From: Jean-Marc Lasgouttes Date: Fri, 18 Jun 2021 11:53:37 +0000 (+0200) Subject: Always remove selection after cursor left/right X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8d90bb99915599d0f9cda16a33a8428895a84e8c;p=features.git Always remove selection after cursor left/right Example: when a selection is set, a `Left' cursor movement would not reset selection when the cursor was at the beginning of buffer. To fix this, it is necessary, when cursor is in top-level text, to avoid the mechnanism (undispatched cursor) that sends the action to the upper level (necessary when the cursor leaves an inset). The change is mechanical and is done for : char-backward, char-forward, char-left, char-right, word-left, word-right, word-left, word-right. It might be possible to factor this code a bit, but there is no evident solution. char-up/down are *not* handled at this point. Fixes part of bug #12310. --- diff --git a/src/Text3.cpp b/src/Text3.cpp index dce6032b2e..ffc5d758df 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -794,24 +794,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bool const cur_moved = cursorForward(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_FORWARD); - // we will probably be moving out the inset, so we should execute - // the depm-mechanism, but only when the cursor has a place to - // go outside this inset, i.e. in a slice above. - if (cur.depth() > 1 && cur.pos() == cur.lastpos() - && cur.pit() == cur.lastpit()) { - // The cursor hasn't changed yet. To give the - // DEPM the possibility of doing something we must - // provide it with two different cursors. - Cursor dummy = cur; - dummy.pos() = dummy.pit() = 0; - if (cur.bv().checkDepm(dummy, cur)) - cur.forceBufferUpdate(); - } + // we will be moving out the inset, so we should execute + // the depm-mechanism. + // The cursor hasn't changed yet. To give the DEPM the + // possibility of doing something we must provide it with + // two different cursors. + Cursor dummy = cur; + dummy.pos() = dummy.pit() = 0; + if (cur.bv().checkDepm(dummy, cur)) + cur.forceBufferUpdate(); } break; } @@ -823,24 +819,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bool const cur_moved = cursorBackward(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_BACKWARD); - // we will probably be moving out the inset, so we should execute - // the depm-mechanism, but only when the cursor has a place to - // go outside this inset, i.e. in a slice above. - if (cur.depth() > 1 && cur.pos() == 0 && cur.pit() == 0) { - // The cursor hasn't changed yet. To give the - // DEPM the possibility of doing something we must - // provide it with two different cursors. - Cursor dummy = cur; - dummy.pos() = cur.lastpos(); - dummy.pit() = cur.lastpit(); - if (cur.bv().checkDepm(dummy, cur)) - cur.forceBufferUpdate(); - } + // we will be moving out the inset, so we should execute + // the depm-mechanism. + // The cursor hasn't changed yet. To give the DEPM the + // possibility of doing something we must provide it with + // two different cursors. + Cursor dummy = cur; + dummy.pos() = cur.lastpos(); + dummy.pit() = cur.lastpit(); + if (cur.bv().checkDepm(dummy, cur)) + cur.forceBufferUpdate(); } break; } @@ -851,8 +844,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT); bool const cur_moved = cursorVisLeft(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_LEFT); } @@ -875,8 +868,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT); bool const cur_moved = cursorVisRight(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_RIGHT); } @@ -1009,8 +1002,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT); bool const cur_moved = cursorVisRightOneWord(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_RIGHT); } @@ -1033,24 +1026,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bool const cur_moved = cursorForwardOneWord(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_FORWARD); - // we will probably be moving out the inset, so we should execute - // the depm-mechanism, but only when the cursor has a place to - // go outside this inset, i.e. in a slice above. - if (cur.depth() > 1 && cur.pos() == cur.lastpos() - && cur.pit() == cur.lastpit()) { - // The cursor hasn't changed yet. To give the - // DEPM the possibility of doing something we must - // provide it with two different cursors. - Cursor dummy = cur; - dummy.pos() = dummy.pit() = 0; - if (cur.bv().checkDepm(dummy, cur)) - cur.forceBufferUpdate(); - } + // we will be moving out the inset, so we should execute + // the depm-mechanism. + // The cursor hasn't changed yet. To give the DEPM the + // possibility of doing something we must provide it with + // two different cursors. + Cursor dummy = cur; + dummy.pos() = dummy.pit() = 0; + if (cur.bv().checkDepm(dummy, cur)) + cur.forceBufferUpdate(); } break; } @@ -1061,8 +1050,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT); bool const cur_moved = cursorVisLeftOneWord(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_LEFT); } @@ -1085,25 +1074,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bool const cur_moved = cursorBackwardOneWord(cur); needsUpdate |= cur_moved; - if (!cur_moved && oldTopSlice == cur.top() - && cur.boundary() == oldBoundary) { + if (!cur_moved && cur.depth() > 1 + && oldTopSlice == cur.top() && cur.boundary() == oldBoundary) { cur.undispatched(); cmd = FuncRequest(LFUN_FINISHED_BACKWARD); - // we will probably be moving out the inset, so we should execute - // the depm-mechanism, but only when the cursor has a place to - // go outside this inset, i.e. in a slice above. - if (cur.depth() > 1 && cur.pos() == 0 - && cur.pit() == 0) { - // The cursor hasn't changed yet. To give the - // DEPM the possibility of doing something we must - // provide it with two different cursors. - Cursor dummy = cur; - dummy.pos() = cur.lastpos(); - dummy.pit() = cur.lastpit(); - if (cur.bv().checkDepm(dummy, cur)) - cur.forceBufferUpdate(); - } + // we will be moving out the inset, so we should execute + // the depm-mechanism. + // The cursor hasn't changed yet. To give the DEPM the + // possibility of doing something we must provide it with + // two different cursors. + Cursor dummy = cur; + dummy.pos() = cur.lastpos(); + dummy.pit() = cur.lastpit(); + if (cur.bv().checkDepm(dummy, cur)) + cur.forceBufferUpdate(); } break; }