Skip to content

Commit 8b51b7f

Browse files
committed
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().
1 parent ad5e563 commit 8b51b7f

5 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/change.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ changed_bytes(linenr_T lnum, colnr_T col)
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

src/ops.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ block_insert(
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 @@ block_insert(
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 @@ block_insert(
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

src/proto/change.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void may_invoke_listeners(buf_T *buf, linenr_T lnum, linenr_T lnume, int added);
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);

src/testdir/test_textprop.vim

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,4 +1314,35 @@ func Test_prop_increment_decrement()
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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1690,
753755
/**/
754756
1689,
755757
/**/

0 commit comments

Comments
 (0)