Skip to content

Commit 6638ec8

Browse files
vanaigrchrisbra
authored andcommitted
patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put
Problem: Incorrect number of trailing spaces inserted for multibyte characters when pasting a blockwise register in blockwise visual mode (VanaIgr) Solution: Skip over trailing UTF-8 bytes when computing the number of trailing spaces (VanaIgr) When pasting in blockwise visual mode, and the register type is <CTRL-V>, Vim aligns the text after the replaced area by inserting spaces after pasted lines that are shorter than the longest line. When a shorter line contains multibyte characters, each trailing UTF-8 byte's width is counted in addition to the width of the character itself. Each trailing byte counts as being 4 cells wide (since it would be displayed as <xx>). closes: #13909 Signed-off-by: VanaIgr <vanaigranov@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 78019df commit 6638ec8

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/register.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,10 @@ do_put(
19031903
spaces = y_width + 1;
19041904
init_chartabsize_arg(&cts, curwin, 0, 0,
19051905
y_array[i], y_array[i]);
1906-
for (j = 0; j < yanklen; j++)
1906+
1907+
while (*cts.cts_ptr != NUL)
19071908
{
1908-
spaces -= lbr_chartabsize(&cts);
1909-
++cts.cts_ptr;
1909+
spaces -= lbr_chartabsize_adv(&cts);
19101910
cts.cts_vcol = 0;
19111911
}
19121912
clear_chartabsize_arg(&cts);

src/testdir/test_put.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ func Test_put_block()
1212
bwipe!
1313
endfunc
1414

15+
func Test_put_block_unicode()
16+
new
17+
call setreg('a', "À\nÀÀ\naaaaaaaaaaaa", "\<C-V>")
18+
call setline(1, [' 1', ' 2', ' 3'])
19+
exe "norm! \<C-V>jj\"ap"
20+
let expected = ['À 1', 'ÀÀ 2', 'aaaaaaaaaaaa3']
21+
call assert_equal(expected, getline(1, 3))
22+
bw!
23+
endfunc
24+
1525
func Test_put_char_block()
1626
new
1727
call setline(1, ['Line 1', 'Line 2'])

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
56,
707709
/**/
708710
55,
709711
/**/

0 commit comments

Comments
 (0)