• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision5adb97bf0b32f2ec2821ea083e4bdf92fcf8728b (tree)
Zeit2020-09-16 04:45:04
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.1690: text properties not adjusted for "I" in Visual block mode

Commit: https://github.com/vim/vim/commit/8b51b7f0f17af149a8ce76e805050977857f9e50
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 15 21:34:18 2020 +0200

patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Problem: Text properties not adjusted for "I" in Visual block mode.
Solution: Call inserted_bytes().

Ändern Zusammenfassung

Diff

diff -r 7509c66a371a -r 5adb97bf0b32 src/change.c
--- a/src/change.c Tue Sep 15 21:00:04 2020 +0200
+++ b/src/change.c Tue Sep 15 21:45:04 2020 +0200
@@ -693,7 +693,7 @@
693693 * Like changed_bytes() but also adjust text properties for "added" bytes.
694694 * When "added" is negative text was deleted.
695695 */
696- static void
696+ void
697697 inserted_bytes(linenr_T lnum, colnr_T col, int added UNUSED)
698698 {
699699 #ifdef FEAT_PROP_POPUP
diff -r 7509c66a371a -r 5adb97bf0b32 src/ops.c
--- a/src/ops.c Tue Sep 15 21:00:04 2020 +0200
+++ b/src/ops.c Tue Sep 15 21:45:04 2020 +0200
@@ -481,6 +481,7 @@
481481 int count = 0; // extra spaces to replace a cut TAB
482482 int spaces = 0; // non-zero if cutting a TAB
483483 colnr_T offset; // pointer along new line
484+ colnr_T startcol; // column where insert starts
484485 unsigned s_len; // STRLEN(s)
485486 char_u *newp, *oldp; // new, old lines
486487 linenr_T lnum; // loop var
@@ -553,9 +554,10 @@
553554
554555 // insert pre-padding
555556 vim_memset(newp + offset, ' ', (size_t)spaces);
557+ startcol = offset + spaces;
556558
557559 // copy the new text
558- mch_memmove(newp + offset + spaces, s, (size_t)s_len);
560+ mch_memmove(newp + startcol, s, (size_t)s_len);
559561 offset += s_len;
560562
561563 if (spaces && !bdp->is_short)
@@ -574,6 +576,10 @@
574576
575577 ml_replace(lnum, newp, FALSE);
576578
579+ if (b_insert)
580+ // correct any text properties
581+ inserted_bytes(lnum, startcol, s_len);
582+
577583 if (lnum == oap->end.lnum)
578584 {
579585 // Set "']" mark to the end of the block instead of the end of
diff -r 7509c66a371a -r 5adb97bf0b32 src/proto/change.pro
--- a/src/proto/change.pro Tue Sep 15 21:00:04 2020 +0200
+++ b/src/proto/change.pro Tue Sep 15 21:45:04 2020 +0200
@@ -9,6 +9,7 @@
99 void invoke_listeners(buf_T *buf);
1010 void remove_listeners(buf_T *buf);
1111 void changed_bytes(linenr_T lnum, colnr_T col);
12+void inserted_bytes(linenr_T lnum, colnr_T col, int added);
1213 void appended_lines(linenr_T lnum, long count);
1314 void appended_lines_mark(linenr_T lnum, long count);
1415 void deleted_lines(linenr_T lnum, long count);
diff -r 7509c66a371a -r 5adb97bf0b32 src/testdir/test_textprop.vim
--- a/src/testdir/test_textprop.vim Tue Sep 15 21:00:04 2020 +0200
+++ b/src/testdir/test_textprop.vim Tue Sep 15 21:45:04 2020 +0200
@@ -1314,4 +1314,35 @@
13141314 call prop_type_delete('test')
13151315 endfunc
13161316
1317+func Test_prop_block_insert()
1318+ new
1319+ call prop_type_add('test', {'highlight': 'ErrorMsg'})
1320+ call setline(1, ['one ', 'two '])
1321+ call prop_add(1, 1, {'length': 3, 'type': 'test'})
1322+ call prop_add(2, 1, {'length': 3, 'type': 'test'})
1323+
1324+ " insert "xx" in the first column of both lines
1325+ exe "normal! gg0\<C-V>jIxx\<Esc>"
1326+ eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
1327+ let expected = [#{id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
1328+ eval prop_list(1)->assert_equal(expected)
1329+ eval prop_list(2)->assert_equal(expected)
1330+
1331+ " insert "yy" inside the text props to make them longer
1332+ exe "normal! gg03l\<C-V>jIyy\<Esc>"
1333+ eval getline(1, 2)->assert_equal(['xxoyyne ', 'xxtyywo '])
1334+ let expected[0].length = 5
1335+ eval prop_list(1)->assert_equal(expected)
1336+ eval prop_list(2)->assert_equal(expected)
1337+
1338+ " insert "zz" after the text props, text props don't change
1339+ exe "normal! gg07l\<C-V>jIzz\<Esc>"
1340+ eval getline(1, 2)->assert_equal(['xxoyynezz ', 'xxtyywozz '])
1341+ eval prop_list(1)->assert_equal(expected)
1342+ eval prop_list(2)->assert_equal(expected)
1343+
1344+ bwipe!
1345+ call prop_type_delete('test')
1346+endfunc
1347+
13171348 " vim: shiftwidth=2 sts=2 expandtab
diff -r 7509c66a371a -r 5adb97bf0b32 src/version.c
--- a/src/version.c Tue Sep 15 21:00:04 2020 +0200
+++ b/src/version.c Tue Sep 15 21:45:04 2020 +0200
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 1690,
755+/**/
754756 1689,
755757 /**/
756758 1688,
Show on old repository browser