vim-patch:8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left

Problem:    CTRL-G U in Insert mode doesn't work to avoid splitting the undo
            sequence for shift-left and shift-right.
Solution:   Also check dont_sync_undo for shifted cursor keys. (Christian
            Brabandt)
75bf3d22f4
This commit is contained in:
Jan Edmund Lazo
2019-06-23 19:37:58 -04:00
parent 7d604a1e61
commit 3dcf2d5c16
2 changed files with 49 additions and 11 deletions

View File

@@ -276,7 +276,7 @@ static int ins_need_undo; /* call u_save() before inserting a
static bool did_add_space = false; // auto_format() added an extra space static bool did_add_space = false; // auto_format() added an extra space
// under the cursor // under the cursor
static TriState dont_sync_undo = kFalse; // CTRL-G U prevents syncing undo static TriState dont_sync_undo = kFalse; // CTRL-G U prevents syncing undo
// for the next left/right cursor // for the next left/right cursor key
static linenr_T o_lnum = 0; static linenr_T o_lnum = 0;
@@ -1037,7 +1037,7 @@ check_pum:
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) { if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_left(); ins_s_left();
} else { } else {
ins_left(dont_sync_undo == kFalse); ins_left();
} }
break; break;
@@ -1050,7 +1050,7 @@ check_pum:
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) { if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_right(); ins_s_right();
} else { } else {
ins_right(dont_sync_undo == kFalse); ins_right();
} }
break; break;
@@ -8103,9 +8103,10 @@ static void ins_mousescroll(int dir)
static void ins_left(bool end_change) static void ins_left(void)
{ {
pos_T tpos; pos_T tpos;
const bool end_change = dont_sync_undo == kFalse; // end undoable change
if ((fdo_flags & FDO_HOR) && KeyTyped) if ((fdo_flags & FDO_HOR) && KeyTyped)
foldOpenCursor(); foldOpenCursor();
@@ -8167,23 +8168,31 @@ static void ins_end(int c)
static void ins_s_left(void) static void ins_s_left(void)
{ {
if ((fdo_flags & FDO_HOR) && KeyTyped) const bool end_change = dont_sync_undo == kFalse; // end undoable change
if ((fdo_flags & FDO_HOR) && KeyTyped) {
foldOpenCursor(); foldOpenCursor();
}
undisplay_dollar(); undisplay_dollar();
if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0) { if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0) {
start_arrow(&curwin->w_cursor); start_arrow_with_change(&curwin->w_cursor, end_change);
if (!end_change) {
AppendCharToRedobuff(K_S_LEFT);
}
(void)bck_word(1L, false, false); (void)bck_word(1L, false, false);
curwin->w_set_curswant = true; curwin->w_set_curswant = true;
} else { } else {
vim_beep(BO_CRSR); vim_beep(BO_CRSR);
} }
dont_sync_undo = kFalse;
} }
/// @param end_change end undoable change /// @param end_change end undoable change
static void ins_right(bool end_change) static void ins_right(void)
{ {
if ((fdo_flags & FDO_HOR) && KeyTyped) const bool end_change = dont_sync_undo == kFalse; // end undoable change
if ((fdo_flags & FDO_HOR) && KeyTyped) {
foldOpenCursor(); foldOpenCursor();
}
undisplay_dollar(); undisplay_dollar();
if (gchar_cursor() != NUL || virtual_active()) { if (gchar_cursor() != NUL || virtual_active()) {
start_arrow_with_change(&curwin->w_cursor, end_change); start_arrow_with_change(&curwin->w_cursor, end_change);
@@ -8220,17 +8229,23 @@ static void ins_right(bool end_change)
static void ins_s_right(void) static void ins_s_right(void)
{ {
if ((fdo_flags & FDO_HOR) && KeyTyped) const bool end_change = dont_sync_undo == kFalse; // end undoable change
if ((fdo_flags & FDO_HOR) && KeyTyped) {
foldOpenCursor(); foldOpenCursor();
}
undisplay_dollar(); undisplay_dollar();
if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
|| gchar_cursor() != NUL) { || gchar_cursor() != NUL) {
start_arrow(&curwin->w_cursor); start_arrow_with_change(&curwin->w_cursor, end_change);
if (!end_change) {
AppendCharToRedobuff(K_S_RIGHT);
}
(void)fwd_word(1L, false, 0); (void)fwd_word(1L, false, 0);
curwin->w_set_curswant = true; curwin->w_set_curswant = true;
} else { } else {
vim_beep(BO_CRSR); vim_beep(BO_CRSR);
} }
dont_sync_undo = kFalse;
} }
static void static void

View File

@@ -187,9 +187,32 @@ func Test_map_cursor()
imapclear imapclear
endfunc endfunc
func Test_map_cursor_ctrl_gU()
" <c-g>U<cursor> works only within a single line
nnoremap c<* *Ncgn<C-r>"<C-G>U<S-Left>
call setline(1, ['foo', 'foobar', '', 'foo'])
call cursor(1,2)
call feedkeys("c<*PREFIX\<esc>.", 'xt')
call assert_equal(['PREFIXfoo', 'foobar', '', 'PREFIXfoo'], getline(1,'$'))
" break undo manually
set ul=1000
exe ":norm! uu"
call assert_equal(['foo', 'foobar', '', 'foo'], getline(1,'$'))
" Test that it does not work if the cursor moves to the previous line
" 2 times <S-Left> move to the previous line
nnoremap c<* *Ncgn<C-r>"<C-G>U<S-Left><C-G>U<S-Left>
call setline(1, ['', ' foo', 'foobar', '', 'foo'])
call cursor(2,3)
call feedkeys("c<*PREFIX\<esc>.", 'xt')
call assert_equal(['PREFIXPREFIX', ' foo', 'foobar', '', 'foo'], getline(1,'$'))
nmapclear
endfunc
" This isn't actually testing a mapping, but similar use of CTRL-G U as above. " This isn't actually testing a mapping, but similar use of CTRL-G U as above.
func Test_break_undo() func Test_break_undo()
:set whichwrap=<,>,[,] set whichwrap=<,>,[,]
call feedkeys("G4o2k", "xt") call feedkeys("G4o2k", "xt")
exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>." exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."
call assert_equal('new line here', getline(line('$') - 3)) call assert_equal('new line here', getline(line('$') - 3))