aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c35
-rw-r--r--src/nvim/testdir/test_mapping.vim25
2 files changed, 49 insertions, 11 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 8040109685..da9b5fde69 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -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
// under the cursor
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;
@@ -1037,7 +1037,7 @@ check_pum:
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_left();
} else {
- ins_left(dont_sync_undo == kFalse);
+ ins_left();
}
break;
@@ -1050,7 +1050,7 @@ check_pum:
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_right();
} else {
- ins_right(dont_sync_undo == kFalse);
+ ins_right();
}
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;
+ const bool end_change = dont_sync_undo == kFalse; // end undoable change
if ((fdo_flags & FDO_HOR) && KeyTyped)
foldOpenCursor();
@@ -8167,23 +8168,31 @@ static void ins_end(int c)
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();
+ }
undisplay_dollar();
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);
curwin->w_set_curswant = true;
} else {
vim_beep(BO_CRSR);
}
+ dont_sync_undo = kFalse;
}
/// @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();
+ }
undisplay_dollar();
if (gchar_cursor() != NUL || virtual_active()) {
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)
{
- if ((fdo_flags & FDO_HOR) && KeyTyped)
+ const bool end_change = dont_sync_undo == kFalse; // end undoable change
+ if ((fdo_flags & FDO_HOR) && KeyTyped) {
foldOpenCursor();
+ }
undisplay_dollar();
if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
|| 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);
curwin->w_set_curswant = true;
} else {
vim_beep(BO_CRSR);
}
+ dont_sync_undo = kFalse;
}
static void
diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim
index 84a118aef2..9f253604ed 100644
--- a/src/nvim/testdir/test_mapping.vim
+++ b/src/nvim/testdir/test_mapping.vim
@@ -187,9 +187,32 @@ func Test_map_cursor()
imapclear
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.
func Test_break_undo()
- :set whichwrap=<,>,[,]
+ set whichwrap=<,>,[,]
call feedkeys("G4o2k", "xt")
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))