mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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)
This commit is contained in:
41
src/edit.c
41
src/edit.c
@@ -236,11 +236,11 @@ static void ins_mousescroll(int dir);
|
|||||||
#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
|
#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
|
||||||
static void ins_tabline(int c);
|
static void ins_tabline(int c);
|
||||||
#endif
|
#endif
|
||||||
static void ins_left(int end_change);
|
static void ins_left(void);
|
||||||
static void ins_home(int c);
|
static void ins_home(int c);
|
||||||
static void ins_end(int c);
|
static void ins_end(int c);
|
||||||
static void ins_s_left(void);
|
static void ins_s_left(void);
|
||||||
static void ins_right(int end_change);
|
static void ins_right(void);
|
||||||
static void ins_s_right(void);
|
static void ins_s_right(void);
|
||||||
static void ins_up(int startcol);
|
static void ins_up(int startcol);
|
||||||
static void ins_pageup(void);
|
static void ins_pageup(void);
|
||||||
@@ -290,10 +290,10 @@ static int ins_need_undo; /* call u_save() before inserting a
|
|||||||
char. Set when edit() is called.
|
char. Set when edit() is called.
|
||||||
after that arrow_used is used. */
|
after that arrow_used is used. */
|
||||||
|
|
||||||
static int did_add_space = FALSE; /* auto_format() added an extra space
|
static int did_add_space = FALSE; // auto_format() added an extra space
|
||||||
under the cursor */
|
// under the cursor
|
||||||
static int dont_sync_undo = FALSE; /* CTRL-G U prevents syncing undo for
|
static int dont_sync_undo = FALSE; // CTRL-G U prevents syncing undo for
|
||||||
the next left/right cursor */
|
// the next left/right cursor key
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* edit(): Start inserting text.
|
* edit(): Start inserting text.
|
||||||
@@ -1284,7 +1284,7 @@ doESCkey:
|
|||||||
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 == FALSE);
|
ins_left();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_S_LEFT: /* <S-Left> */
|
case K_S_LEFT: /* <S-Left> */
|
||||||
@@ -1296,7 +1296,7 @@ doESCkey:
|
|||||||
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 == FALSE);
|
ins_right();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case K_S_RIGHT: /* <S-Right> */
|
case K_S_RIGHT: /* <S-Right> */
|
||||||
@@ -9291,10 +9291,10 @@ ins_horscroll(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ins_left(
|
ins_left(void)
|
||||||
int end_change) /* end undoable change */
|
|
||||||
{
|
{
|
||||||
pos_T tpos;
|
pos_T tpos;
|
||||||
|
int end_change = dont_sync_undo == FALSE; // end undoable change
|
||||||
|
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
||||||
@@ -9378,8 +9378,9 @@ ins_end(int c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ins_s_left(void)
|
ins_s_left()
|
||||||
{
|
{
|
||||||
|
int end_change = dont_sync_undo == FALSE; // end undoable change
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
@@ -9387,18 +9388,22 @@ ins_s_left(void)
|
|||||||
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 = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ins_right(
|
ins_right(void)
|
||||||
int end_change) /* end undoable change */
|
|
||||||
{
|
{
|
||||||
|
int end_change = dont_sync_undo == FALSE; // end undoable change
|
||||||
|
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
@@ -9442,8 +9447,9 @@ ins_right(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ins_s_right(void)
|
ins_s_right()
|
||||||
{
|
{
|
||||||
|
int end_change = dont_sync_undo == FALSE; // end undoable change
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
if ((fdo_flags & FDO_HOR) && KeyTyped)
|
||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
@@ -9452,12 +9458,15 @@ ins_s_right(void)
|
|||||||
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 = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -140,9 +140,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))
|
||||||
|
@@ -775,6 +775,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1055,
|
||||||
/**/
|
/**/
|
||||||
1054,
|
1054,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user