mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.1.0204: Backspace inserts spaces with virtual text and 'smarttab'
Problem: Backspace inserts spaces with virtual text and 'smarttab'. Solution: Ignore virtual text and wrapping when backspacing. (zeertzjq) related: neovim/neovim#28005 closes: #14296 Co-authored-by: VanaIgr <vanaigranov@gmail.com> Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
ab01adf7c6
commit
0185c77014
72
src/edit.c
72
src/edit.c
@ -3958,10 +3958,9 @@ ins_del(void)
|
|||||||
* Delete one character for ins_bs().
|
* Delete one character for ins_bs().
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ins_bs_one(colnr_T *vcolp)
|
ins_bs_one(void)
|
||||||
{
|
{
|
||||||
dec_cursor();
|
dec_cursor();
|
||||||
getvcol(curwin, &curwin->w_cursor, vcolp, NULL, NULL);
|
|
||||||
if (State & REPLACE_FLAG)
|
if (State & REPLACE_FLAG)
|
||||||
{
|
{
|
||||||
// Don't delete characters before the insert point when in
|
// Don't delete characters before the insert point when in
|
||||||
@ -4212,19 +4211,38 @@ ins_bs(
|
|||||||
|| arrow_used))))))
|
|| arrow_used))))))
|
||||||
{
|
{
|
||||||
int ts;
|
int ts;
|
||||||
colnr_T vcol;
|
colnr_T vcol = 0;
|
||||||
colnr_T want_vcol;
|
colnr_T want_vcol;
|
||||||
colnr_T start_vcol;
|
char_u *line;
|
||||||
|
char_u *ptr;
|
||||||
|
char_u *end_ptr;
|
||||||
|
char_u *space_ptr;
|
||||||
|
colnr_T space_vcol = 0;
|
||||||
|
int prev_space = FALSE;
|
||||||
|
colnr_T want_col;
|
||||||
|
|
||||||
*inserted_space_p = FALSE;
|
*inserted_space_p = FALSE;
|
||||||
// Compute the virtual column where we want to be. Since
|
|
||||||
// 'showbreak' may get in the way, need to get the last column of
|
space_ptr = ptr = line = ml_get_curline();
|
||||||
// the previous character.
|
end_ptr = line + curwin->w_cursor.col;
|
||||||
getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
|
|
||||||
start_vcol = vcol;
|
// Find the last whitespace that is preceded by non-whitespace.
|
||||||
dec_cursor();
|
// Use chartabsize() so that virtual text and wrapping are ignored.
|
||||||
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
|
do {
|
||||||
inc_cursor();
|
int cur_space = VIM_ISWHITE(*ptr);
|
||||||
|
|
||||||
|
if (!prev_space && cur_space)
|
||||||
|
{
|
||||||
|
space_ptr = ptr;
|
||||||
|
space_vcol = vcol;
|
||||||
|
}
|
||||||
|
vcol += chartabsize(ptr, vcol);
|
||||||
|
MB_PTR_ADV(ptr);
|
||||||
|
prev_space = cur_space;
|
||||||
|
} while (ptr < end_ptr);
|
||||||
|
|
||||||
|
// Compute the virtual column where we want to be.
|
||||||
|
want_vcol = vcol - 1;
|
||||||
#ifdef FEAT_VARTABS
|
#ifdef FEAT_VARTABS
|
||||||
if (p_sta && in_indent)
|
if (p_sta && in_indent)
|
||||||
{
|
{
|
||||||
@ -4242,13 +4260,25 @@ ins_bs(
|
|||||||
want_vcol = (want_vcol / ts) * ts;
|
want_vcol = (want_vcol / ts) * ts;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// delete characters until we are at or before want_vcol
|
// Find the position to stop backspacing.
|
||||||
while (vcol > want_vcol && curwin->w_cursor.col > 0
|
// Use chartabsize() so that virtual text and wrapping are ignored.
|
||||||
&& (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc)))
|
while (TRUE)
|
||||||
ins_bs_one(&vcol);
|
{
|
||||||
|
int size = chartabsize(space_ptr, space_vcol);
|
||||||
|
|
||||||
// insert extra spaces until we are at want_vcol
|
if (space_vcol + size > want_vcol)
|
||||||
while (vcol < want_vcol)
|
break;
|
||||||
|
space_vcol += size;
|
||||||
|
MB_PTR_ADV(space_ptr);
|
||||||
|
}
|
||||||
|
want_col = space_ptr - line;
|
||||||
|
|
||||||
|
// Delete characters until we are at or before want_col.
|
||||||
|
while (curwin->w_cursor.col > want_col)
|
||||||
|
ins_bs_one();
|
||||||
|
|
||||||
|
// Insert extra spaces until we are at want_vcol.
|
||||||
|
for (; space_vcol < want_vcol; space_vcol++)
|
||||||
{
|
{
|
||||||
// Remember the first char we inserted
|
// Remember the first char we inserted
|
||||||
if (curwin->w_cursor.lnum == Insstart_orig.lnum
|
if (curwin->w_cursor.lnum == Insstart_orig.lnum
|
||||||
@ -4263,13 +4293,7 @@ ins_bs(
|
|||||||
if ((State & REPLACE_FLAG))
|
if ((State & REPLACE_FLAG))
|
||||||
replace_push(NUL);
|
replace_push(NUL);
|
||||||
}
|
}
|
||||||
getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are now back where we started delete one character. Can
|
|
||||||
// happen when using 'sts' and 'linebreak'.
|
|
||||||
if (vcol >= start_vcol)
|
|
||||||
ins_bs_one(&vcol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,8 +6,6 @@ endif
|
|||||||
|
|
||||||
source check.vim
|
source check.vim
|
||||||
source screendump.vim
|
source screendump.vim
|
||||||
|
|
||||||
" Needed for testing basic rightleft: Test_edit_rightleft
|
|
||||||
source view_util.vim
|
source view_util.vim
|
||||||
|
|
||||||
" Needs to come first until the bug in getchar() is
|
" Needs to come first until the bug in getchar() is
|
||||||
@ -2158,4 +2156,113 @@ func Test_edit_Ctrl_RSB()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func s:check_backspace(expected)
|
||||||
|
let g:actual = []
|
||||||
|
inoremap <buffer> <F2> <Cmd>let g:actual += [getline('.')]<CR>
|
||||||
|
set backspace=indent,eol,start
|
||||||
|
|
||||||
|
exe "normal $i" .. repeat("\<BS>\<F2>", len(a:expected))
|
||||||
|
call assert_equal(a:expected, g:actual)
|
||||||
|
|
||||||
|
set backspace&
|
||||||
|
iunmap <buffer> <F2>
|
||||||
|
unlet g:actual
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that backspace works with 'smarttab' and mixed Tabs and spaces.
|
||||||
|
func Test_edit_backspace_smarttab_mixed()
|
||||||
|
call NewWindow(1, 30)
|
||||||
|
setlocal smarttab tabstop=4 shiftwidth=4
|
||||||
|
call setline(1, "\t \t \t a")
|
||||||
|
call s:check_backspace([
|
||||||
|
\ "\t \t \ta",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \ta",
|
||||||
|
\ "\t a",
|
||||||
|
\ "\ta",
|
||||||
|
\ "a",
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
call CloseWindow()
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that backspace works with 'smarttab' and 'varsofttabstop'.
|
||||||
|
func Test_edit_backspace_smarttab_varsofttabstop()
|
||||||
|
CheckFeature vartabs
|
||||||
|
|
||||||
|
call NewWindow(1, 30)
|
||||||
|
setlocal smarttab tabstop=8 varsofttabstop=6,2,5,3
|
||||||
|
call setline(1, "a\t \t a")
|
||||||
|
call s:check_backspace([
|
||||||
|
\ "a\t \ta",
|
||||||
|
\ "a\t a",
|
||||||
|
\ "a\ta",
|
||||||
|
\ "a a",
|
||||||
|
\ "aa",
|
||||||
|
\ "a",
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
call CloseWindow()
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that backspace works with 'smarttab' when a Tab is shown as "^I".
|
||||||
|
func Test_edit_backspace_smarttab_list()
|
||||||
|
call NewWindow(1, 30)
|
||||||
|
setlocal smarttab tabstop=4 shiftwidth=4 list listchars=
|
||||||
|
call setline(1, "\t \t \t a")
|
||||||
|
call s:check_backspace([
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \ta",
|
||||||
|
\ "\t a",
|
||||||
|
\ "a",
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
call CloseWindow()
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that backspace works with 'smarttab' and 'breakindent'.
|
||||||
|
func Test_edit_backspace_smarttab_breakindent()
|
||||||
|
CheckFeature linebreak
|
||||||
|
|
||||||
|
call NewWindow(3, 17)
|
||||||
|
setlocal smarttab tabstop=4 shiftwidth=4 breakindent breakindentopt=min:5
|
||||||
|
call setline(1, "\t \t \t a")
|
||||||
|
call s:check_backspace([
|
||||||
|
\ "\t \t \ta",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \ta",
|
||||||
|
\ "\t a",
|
||||||
|
\ "\ta",
|
||||||
|
\ "a",
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
call CloseWindow()
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that backspace works with 'smarttab' and virtual text.
|
||||||
|
func Test_edit_backspace_smarttab_virtual_text()
|
||||||
|
CheckFeature textprop
|
||||||
|
|
||||||
|
call NewWindow(1, 50)
|
||||||
|
setlocal smarttab tabstop=4 shiftwidth=4
|
||||||
|
call setline(1, "\t \t \t a")
|
||||||
|
call prop_type_add('theprop', {})
|
||||||
|
call prop_add(1, 3, {'type': 'theprop', 'text': 'text'})
|
||||||
|
call s:check_backspace([
|
||||||
|
\ "\t \t \ta",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \t a",
|
||||||
|
\ "\t \ta",
|
||||||
|
\ "\t a",
|
||||||
|
\ "\ta",
|
||||||
|
\ "a",
|
||||||
|
\ ])
|
||||||
|
|
||||||
|
call CloseWindow()
|
||||||
|
call prop_type_delete('theprop')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@ -704,6 +704,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 */
|
||||||
|
/**/
|
||||||
|
204,
|
||||||
/**/
|
/**/
|
||||||
203,
|
203,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user