From 8ede7a069419e0e01368c65a2d0c79d6332aa6cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 28 Mar 2024 10:30:08 +0100 Subject: patch 9.1.0218: Unnecessary multiplications in backspace code Problem: Unnecessary multiplications in backspace code, as "col / ts * ts" is the same as "col - col % ts". Solution: Change "col / ts * ts" to "col - col % ts". Adjust the loop and the comments ins_bs() to be easier to understand. Update tests to reset 'smarttab' properly. (zeertzjq) closes: #14308 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt --- src/testdir/test_edit.vim | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/testdir/test_edit.vim') diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim index fbe7b9ba19..5e3e9cbe13 100644 --- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -2044,7 +2044,10 @@ func Test_edit_revins() 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\:" + call assert_equal(['one two three:ruof'], getline(1, '$')) + set revins& backspace& bw! endfunc @@ -2161,7 +2164,7 @@ func s:check_backspace(expected) inoremap let g:actual += [getline('.')] set backspace=indent,eol,start - exe "normal $i" .. repeat("\\", len(a:expected)) + exe "normal i" .. repeat("\\", len(a:expected)) call assert_equal(a:expected, g:actual) set backspace& @@ -2171,9 +2174,12 @@ endfunc " 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", @@ -2185,15 +2191,19 @@ func Test_edit_backspace_smarttab_mixed() \ ]) 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", @@ -2204,13 +2214,17 @@ func Test_edit_backspace_smarttab_varsofttabstop() \ ]) 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", @@ -2220,15 +2234,19 @@ func Test_edit_backspace_smarttab_list() \ ]) 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", @@ -2240,17 +2258,21 @@ func Test_edit_backspace_smarttab_breakindent() \ ]) 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", @@ -2263,6 +2285,7 @@ func Test_edit_backspace_smarttab_virtual_text() call CloseWindow() call prop_type_delete('theprop') + set smarttab& endfunc " vim: shiftwidth=2 sts=2 expandtab -- cgit v1.2.3