diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-26 05:42:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-26 05:42:56 +0800 |
commit | 7e386308746e61cfdf0ca757a40122cbbceb7feb (patch) | |
tree | 9e0a3a72b480e2a42cc8598547b3bfd22d789a91 /src/nvim/edit.c | |
parent | 14839c5d18c2bef7bdd41944b059603a8589523e (diff) | |
download | rneovim-7e386308746e61cfdf0ca757a40122cbbceb7feb.tar.gz rneovim-7e386308746e61cfdf0ca757a40122cbbceb7feb.tar.bz2 rneovim-7e386308746e61cfdf0ca757a40122cbbceb7feb.zip |
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
https://github.com/vim/vim/commit/0185c7701434f1fbbf83fecd6384a19c1d2fc44e
Co-authored-by: VanaIgr <vanaigranov@gmail.com>
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 8 |
1 files changed, 7 insertions, 1 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) { |