summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-15 21:34:18 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-15 21:34:18 +0200
commit8b51b7f0f17af149a8ce76e805050977857f9e50 (patch)
tree62937457eb147bf903de64ec6ef863e97db20abd
parentad5e5631c5dc93a50bbe637be254c5e9968848ea (diff)
downloadvim-git-8b51b7f0f17af149a8ce76e805050977857f9e50.tar.gz
patch 8.2.1690: text properties not adjusted for "I" in Visual block modev8.2.1690
Problem: Text properties not adjusted for "I" in Visual block mode. Solution: Call inserted_bytes().
-rw-r--r--src/change.c2
-rw-r--r--src/ops.c8
-rw-r--r--src/proto/change.pro1
-rw-r--r--src/testdir/test_textprop.vim31
-rw-r--r--src/version.c2
5 files changed, 42 insertions, 2 deletions
diff --git a/src/change.c b/src/change.c
index 3a823b629..44c2f0480 100644
--- a/src/change.c
+++ b/src/change.c
@@ -693,7 +693,7 @@ changed_bytes(linenr_T lnum, colnr_T col)
* Like changed_bytes() but also adjust text properties for "added" bytes.
* When "added" is negative text was deleted.
*/
- static void
+ void
inserted_bytes(linenr_T lnum, colnr_T col, int added UNUSED)
{
#ifdef FEAT_PROP_POPUP
diff --git a/src/ops.c b/src/ops.c
index 2988a185b..d57294034 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -481,6 +481,7 @@ block_insert(
int count = 0; // extra spaces to replace a cut TAB
int spaces = 0; // non-zero if cutting a TAB
colnr_T offset; // pointer along new line
+ colnr_T startcol; // column where insert starts
unsigned s_len; // STRLEN(s)
char_u *newp, *oldp; // new, old lines
linenr_T lnum; // loop var
@@ -553,9 +554,10 @@ block_insert(
// insert pre-padding
vim_memset(newp + offset, ' ', (size_t)spaces);
+ startcol = offset + spaces;
// copy the new text
- mch_memmove(newp + offset + spaces, s, (size_t)s_len);
+ mch_memmove(newp + startcol, s, (size_t)s_len);
offset += s_len;
if (spaces && !bdp->is_short)
@@ -574,6 +576,10 @@ block_insert(
ml_replace(lnum, newp, FALSE);
+ if (b_insert)
+ // correct any text properties
+ inserted_bytes(lnum, startcol, s_len);
+
if (lnum == oap->end.lnum)
{
// Set "']" mark to the end of the block instead of the end of
diff --git a/src/proto/change.pro b/src/proto/change.pro
index badb19dbd..69ba2a6b0 100644
--- a/src/proto/change.pro
+++ b/src/proto/change.pro
@@ -9,6 +9,7 @@ void may_invoke_listeners(buf_T *buf, linenr_T lnum, linenr_T lnume, int added);
void invoke_listeners(buf_T *buf);
void remove_listeners(buf_T *buf);
void changed_bytes(linenr_T lnum, colnr_T col);
+void inserted_bytes(linenr_T lnum, colnr_T col, int added);
void appended_lines(linenr_T lnum, long count);
void appended_lines_mark(linenr_T lnum, long count);
void deleted_lines(linenr_T lnum, long count);
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index ae84cf974..5bd7e95c3 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -1314,4 +1314,35 @@ func Test_prop_increment_decrement()
call prop_type_delete('test')
endfunc
+func Test_prop_block_insert()
+ new
+ call prop_type_add('test', {'highlight': 'ErrorMsg'})
+ call setline(1, ['one ', 'two '])
+ call prop_add(1, 1, {'length': 3, 'type': 'test'})
+ call prop_add(2, 1, {'length': 3, 'type': 'test'})
+
+ " insert "xx" in the first column of both lines
+ exe "normal! gg0\<C-V>jIxx\<Esc>"
+ eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
+ let expected = [#{id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
+ eval prop_list(1)->assert_equal(expected)
+ eval prop_list(2)->assert_equal(expected)
+
+ " insert "yy" inside the text props to make them longer
+ exe "normal! gg03l\<C-V>jIyy\<Esc>"
+ eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
+ let expected[0].length = 5
+ eval prop_list(1)->assert_equal(expected)
+ eval prop_list(2)->assert_equal(expected)
+
+ " insert "zz" after the text props, text props don't change
+ exe "normal! gg07l\<C-V>jIzz\<Esc>"
+ eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
+ eval prop_list(1)->assert_equal(expected)
+ eval prop_list(2)->assert_equal(expected)
+
+ bwipe!
+ call prop_type_delete('test')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index f4b02418e..6aa02b474 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1690,
+/**/
1689,
/**/
1688,