mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.1.0204: Backspace inserts spaces with virtual text and 'smarttab' (#28032)
Problem: Backspace inserts spaces with virtual text and 'smarttab'.
Solution: Ignore virtual text and wrapping when backspacing.
(zeertzjq)
related: neovim/neovim#28005
closes: vim/vim#14296
0185c77014
Co-authored-by: VanaIgr <vanaigranov@gmail.com>
This commit is contained in:
parent
14839c5d18
commit
7e38630874
@ -3837,7 +3837,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
*inserted_space_p = false;
|
*inserted_space_p = false;
|
||||||
|
|
||||||
bool const use_ts = !curwin->w_p_list || curwin->w_p_lcs_chars.tab1;
|
bool const use_ts = !curwin->w_p_list || curwin->w_p_lcs_chars.tab1;
|
||||||
char *const line = ml_get_buf(curbuf, curwin->w_cursor.lnum);
|
char *const line = get_cursor_line_ptr();
|
||||||
char *const end_ptr = line + curwin->w_cursor.col;
|
char *const end_ptr = line + curwin->w_cursor.col;
|
||||||
|
|
||||||
colnr_T vcol = 0;
|
colnr_T vcol = 0;
|
||||||
@ -3845,6 +3845,9 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
StrCharInfo sci = utf_ptr2StrCharInfo(line);
|
StrCharInfo sci = utf_ptr2StrCharInfo(line);
|
||||||
StrCharInfo space_sci = sci;
|
StrCharInfo space_sci = sci;
|
||||||
bool prev_space = false;
|
bool prev_space = false;
|
||||||
|
|
||||||
|
// Find the last whitespace that is preceded by non-whitespace.
|
||||||
|
// Use charsize_nowrap() so that virtual text and wrapping are ignored.
|
||||||
while (sci.ptr < end_ptr) {
|
while (sci.ptr < end_ptr) {
|
||||||
bool cur_space = ascii_iswhite(sci.chr.value);
|
bool cur_space = ascii_iswhite(sci.chr.value);
|
||||||
if (!prev_space && cur_space) {
|
if (!prev_space && cur_space) {
|
||||||
@ -3856,6 +3859,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
prev_space = cur_space;
|
prev_space = cur_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute the virtual column where we want to be.
|
||||||
colnr_T want_vcol = vcol - 1;
|
colnr_T want_vcol = vcol - 1;
|
||||||
if (want_vcol <= 0) {
|
if (want_vcol <= 0) {
|
||||||
want_vcol = 0;
|
want_vcol = 0;
|
||||||
@ -3865,6 +3869,8 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
|
|||||||
want_vcol = tabstop_start(want_vcol, get_sts_value(), curbuf->b_p_vsts_array);
|
want_vcol = tabstop_start(want_vcol, get_sts_value(), curbuf->b_p_vsts_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the position to stop backspacing.
|
||||||
|
// Use charsize_nowrap() so that virtual text and wrapping are ignored.
|
||||||
while (true) {
|
while (true) {
|
||||||
int size = charsize_nowrap(curbuf, use_ts, space_vcol, space_sci.chr.value);
|
int size = charsize_nowrap(curbuf, use_ts, space_vcol, space_sci.chr.value);
|
||||||
if (space_vcol + size > want_vcol) {
|
if (space_vcol + size > want_vcol) {
|
||||||
|
@ -44,6 +44,8 @@
|
|||||||
/// @param col
|
/// @param col
|
||||||
///
|
///
|
||||||
/// @return Number of cells.
|
/// @return Number of cells.
|
||||||
|
///
|
||||||
|
/// @see charsize_nowrap()
|
||||||
int win_chartabsize(win_T *wp, char *p, colnr_T col)
|
int win_chartabsize(win_T *wp, char *p, colnr_T col)
|
||||||
{
|
{
|
||||||
buf_T *buf = wp->w_buffer;
|
buf_T *buf = wp->w_buffer;
|
||||||
@ -376,6 +378,8 @@ CharSize charsize_fast(CharsizeArg *csarg, colnr_T const vcol, int32_t const cur
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of cells taken up on the screen at given virtual column.
|
/// Get the number of cells taken up on the screen at given virtual column.
|
||||||
|
///
|
||||||
|
/// @see win_chartabsize()
|
||||||
int charsize_nowrap(buf_T *buf, bool use_tabstop, colnr_T vcol, int32_t cur_char)
|
int charsize_nowrap(buf_T *buf, bool use_tabstop, colnr_T vcol, int32_t cur_char)
|
||||||
{
|
{
|
||||||
if (cur_char == TAB && use_tabstop) {
|
if (cur_char == TAB && use_tabstop) {
|
||||||
|
@ -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
|
||||||
@ -2153,4 +2151,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
|
||||||
|
Loading…
Reference in New Issue
Block a user