aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c8
-rw-r--r--src/nvim/plines.c4
-rw-r--r--test/old/testdir/test_edit.vim111
3 files changed, 120 insertions, 3 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 0cbc895328..5ae5267364 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -3837,7 +3837,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
*inserted_space_p = false;
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;
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 space_sci = sci;
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) {
bool cur_space = ascii_iswhite(sci.chr.value);
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;
}
+ // Compute the virtual column where we want to be.
colnr_T want_vcol = vcol - 1;
if (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);
}
+ // Find the position to stop backspacing.
+ // Use charsize_nowrap() so that virtual text and wrapping are ignored.
while (true) {
int size = charsize_nowrap(curbuf, use_ts, space_vcol, space_sci.chr.value);
if (space_vcol + size > want_vcol) {
diff --git a/src/nvim/plines.c b/src/nvim/plines.c
index 3c1297968f..1d5b043907 100644
--- a/src/nvim/plines.c
+++ b/src/nvim/plines.c
@@ -44,6 +44,8 @@
/// @param col
///
/// @return Number of cells.
+///
+/// @see charsize_nowrap()
int win_chartabsize(win_T *wp, char *p, colnr_T col)
{
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.
+///
+/// @see win_chartabsize()
int charsize_nowrap(buf_T *buf, bool use_tabstop, colnr_T vcol, int32_t cur_char)
{
if (cur_char == TAB && use_tabstop) {
diff --git a/test/old/testdir/test_edit.vim b/test/old/testdir/test_edit.vim
index 67143ab524..8281b3d495 100644
--- a/test/old/testdir/test_edit.vim
+++ b/test/old/testdir/test_edit.vim
@@ -6,8 +6,6 @@ endif
source check.vim
source screendump.vim
-
-" Needed for testing basic rightleft: Test_edit_rightleft
source view_util.vim
" Needs to come first until the bug in getchar() is
@@ -2153,4 +2151,113 @@ func Test_edit_Ctrl_RSB()
bwipe!
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