&& (!*inserted_space_p
|| arrow_used))))))
{
- int ts;
colnr_T vcol = 0;
colnr_T want_vcol;
char_u *line;
char_u *ptr;
- char_u *end_ptr;
+ char_u *cursor_ptr;
char_u *space_ptr;
colnr_T space_vcol = 0;
int prev_space = FALSE;
*inserted_space_p = FALSE;
space_ptr = ptr = line = ml_get_curline();
- end_ptr = line + curwin->w_cursor.col;
+ cursor_ptr = line + curwin->w_cursor.col;
- // Find the last whitespace that is preceded by non-whitespace.
+ // Compute virtual column of cursor position, and find the last
+ // whitespace before cursor that is preceded by non-whitespace.
// Use chartabsize() so that virtual text and wrapping are ignored.
- do {
+ while (ptr < cursor_ptr)
+ {
int cur_space = VIM_ISWHITE(*ptr);
if (!prev_space && cur_space)
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
+ want_vcol = vcol > 0 ? vcol - 1 : 0;
if (p_sta && in_indent)
- {
- ts = (int)get_sw_value(curbuf);
- want_vcol = (want_vcol / ts) * ts;
- }
+ want_vcol -= want_vcol % (int)get_sw_value(curbuf);
else
+#ifdef FEAT_VARTABS
want_vcol = tabstop_start(want_vcol, get_sts_value(),
curbuf->b_p_vsts_array);
#else
- if (p_sta && in_indent)
- ts = (int)get_sw_value(curbuf);
- else
- ts = (int)get_sts_value();
- want_vcol = (want_vcol / ts) * ts;
+ want_vcol -= want_vcol % (int)get_sts_value();
#endif
// Find the position to stop backspacing.
call setline(1, 'one two three')
exe "normal! wi\nfour"
call assert_equal(['one two three', 'ruof'], getline(1, '$'))
- set revins&
+ set backspace=indent,eol,start
+ exe "normal! ggA\<BS>:"
+ call assert_equal(['one two three:ruof'], getline(1, '$'))
+ set revins& backspace&
bw!
endfunc
inoremap <buffer> <F2> <Cmd>let g:actual += [getline('.')]<CR>
set backspace=indent,eol,start
- exe "normal $i" .. repeat("\<BS>\<F2>", len(a:expected))
+ exe "normal i" .. repeat("\<BS>\<F2>", len(a:expected))
call assert_equal(a:expected, g:actual)
set backspace&
" Test that backspace works with 'smarttab' and mixed Tabs and spaces.
func Test_edit_backspace_smarttab_mixed()
+ set smarttab
call NewWindow(1, 30)
- setlocal smarttab tabstop=4 shiftwidth=4
+ setlocal tabstop=4 shiftwidth=4
+
call setline(1, "\t \t \t a")
+ normal! $
call s:check_backspace([
\ "\t \t \ta",
\ "\t \t a",
\ ])
call CloseWindow()
+ set smarttab&
endfunc
" Test that backspace works with 'smarttab' and 'varsofttabstop'.
func Test_edit_backspace_smarttab_varsofttabstop()
CheckFeature vartabs
+ set smarttab
call NewWindow(1, 30)
- setlocal smarttab tabstop=8 varsofttabstop=6,2,5,3
+ setlocal tabstop=8 varsofttabstop=6,2,5,3
+
call setline(1, "a\t \t a")
+ normal! $
call s:check_backspace([
\ "a\t \ta",
\ "a\t a",
\ ])
call CloseWindow()
+ set smarttab&
endfunc
" Test that backspace works with 'smarttab' when a Tab is shown as "^I".
func Test_edit_backspace_smarttab_list()
+ set smarttab
call NewWindow(1, 30)
- setlocal smarttab tabstop=4 shiftwidth=4 list listchars=
+ setlocal tabstop=4 shiftwidth=4 list listchars=
+
call setline(1, "\t \t \t a")
+ normal! $
call s:check_backspace([
\ "\t \t a",
\ "\t \t a",
\ ])
call CloseWindow()
+ set smarttab&
endfunc
" Test that backspace works with 'smarttab' and 'breakindent'.
func Test_edit_backspace_smarttab_breakindent()
CheckFeature linebreak
+ set smarttab
call NewWindow(3, 17)
- setlocal smarttab tabstop=4 shiftwidth=4 breakindent breakindentopt=min:5
+ setlocal tabstop=4 shiftwidth=4 breakindent breakindentopt=min:5
+
call setline(1, "\t \t \t a")
+ normal! $
call s:check_backspace([
\ "\t \t \ta",
\ "\t \t a",
\ ])
call CloseWindow()
+ set smarttab&
endfunc
" Test that backspace works with 'smarttab' and virtual text.
func Test_edit_backspace_smarttab_virtual_text()
CheckFeature textprop
+ set smarttab
call NewWindow(1, 50)
- setlocal smarttab tabstop=4 shiftwidth=4
+ setlocal 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'})
+ normal! $
call s:check_backspace([
\ "\t \t \ta",
\ "\t \t a",
call CloseWindow()
call prop_type_delete('theprop')
+ set smarttab&
endfunc
" vim: shiftwidth=2 sts=2 expandtab