patch 9.1.0153: Text properties corrupted with fo+=aw and backspace
Commit:
https://github.com/vim/vim/commit/7ac1145fbebb66dfee325dc5265309877d941c4e
Author: zeertzjq <[email protected]>
Date: Wed Mar 6 20:54:22 2024 +0100
patch 9.1.0153: Text properties corrupted with fo+=aw and backspace
Problem: Text properties corrupted with fo+=aw and backspace
Solution: Allocate line and move text properties
(zeertzjq)
closes: #14147
Signed-off-by: zeertzjq <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/edit.c b/src/edit.c
index d7c80ffcd..998647cd8 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -4101,12 +4101,30 @@ ins_bs(
&& has_format_option(FO_WHITE_PAR))
{
char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
- TRUE);
- int len;
+ FALSE);
+ int len = ml_get_curline_len();
- len = (int)STRLEN(ptr);
if (len > 0 && ptr[len - 1] == ' ')
- ptr[len - 1] = NUL;
+ {
+ char_u *newp = alloc(curbuf->b_ml.ml_line_len - 1);
+
+ if (newp != NULL)
+ {
+ mch_memmove(newp, ptr, len - 1);
+ newp[len - 1] = NUL;
+ if (curbuf->b_ml.ml_line_len > len + 1)
+ mch_memmove(newp + len, ptr + len + 1,
+ curbuf->b_ml.ml_line_len - len - 1);
+
+ if (curbuf->b_ml.ml_flags
+ & (ML_LINE_DIRTY | ML_ALLOCATED))
+ vim_free(curbuf->b_ml.ml_line_ptr);
+ curbuf->b_ml.ml_line_ptr = newp;
+ curbuf->b_ml.ml_line_len--;
+ curbuf->b_ml.ml_line_textlen--;
+ curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
+ }
+ }
}
(void)do_join(2, FALSE, FALSE, FALSE, FALSE);
diff --git a/src/testdir/test_comments.vim b/src/testdir/test_comments.vim
index c34b85c42..67454f477 100644
--- a/src/testdir/test_comments.vim
+++ b/src/testdir/test_comments.vim
@@ -237,6 +237,12 @@ func Test_comment_autoformat()
call feedkeys("aone
two
", 'xt')
call assert_equal(['one', 'two', ''], getline(1, '$'))
+ set backspace=indent,eol,start
+ %d
+ call feedkeys("aone
\<BS>", 'xt')
+ call assert_equal(['one'], getline(1, '$'))
+ set backspace&
+
close!
endfunc
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 7542c08da..1074b0ca5 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -4466,4 +4466,23 @@ func Test_textprop_notype_join()
bwipe!
endfunc
+" This was causing text property corruption.
+func Test_textprop_backspace_fo_aw()
+ new
+ call setline(1, 'foobar')
+ call prop_type_add('test', {'highlight': 'ErrorMsg'})
+ call prop_add(1, 1, {'type': 'test', 'length': 3})
+ set backspace=indent,eol,start
+ setlocal formatoptions+=aw
+ call feedkeys("A \<CR>\<BS>\<Esc>", 'tx')
+ call assert_equal('foobar', getline(1))
+ call assert_equal([
+ \ #{id: 0, col: 1, start: 1, end: 1, type_bufnr: 0,
+ \ type: 'test', length: 3}], prop_list(1))
+
+ bwipe!
+ set backspace&
+ call prop_type_delete('test')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index cf0af4304..8ada6585d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 153,
/**/
152,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/E1rhxQx-003Xxf-Js%40256bit.org.