Skip to content

Commit 4d07253

Browse files
committed
patch 8.2.3677: after a put the '] mark is on the last byte
Problem: After a put the '] mark is on the last byte of a multi-byte character. Solution: Move it to the first byte. (closes #9047)
1 parent 309ce25 commit 4d07253

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/register.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ do_put(
20042004
{
20052005
linenr_T end_lnum = 0; // init for gcc
20062006
linenr_T start_lnum = lnum;
2007+
int first_byte_off = 0;
20072008

20082009
if (VIsual_active)
20092010
{
@@ -2065,6 +2066,10 @@ do_put(
20652066
}
20662067
STRMOVE(ptr, oldp + col);
20672068
ml_replace(lnum, newp, FALSE);
2069+
2070+
// compute the byte offset for the last character
2071+
first_byte_off = mb_head_off(newp, ptr - 1);
2072+
20682073
// Place cursor on last putted char.
20692074
if (lnum == curwin->w_cursor.lnum)
20702075
{
@@ -2080,10 +2085,15 @@ do_put(
20802085
lnum--;
20812086
}
20822087

2088+
// put '] at the first byte of the last character
20832089
curbuf->b_op_end = curwin->w_cursor;
2090+
curbuf->b_op_end.col -= first_byte_off;
2091+
20842092
// For "CTRL-O p" in Insert mode, put cursor after last char
20852093
if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND)))
20862094
++curwin->w_cursor.col;
2095+
else
2096+
curwin->w_cursor.col -= first_byte_off;
20872097
changed_bytes(lnum, col);
20882098
}
20892099
else
@@ -2198,12 +2208,14 @@ do_put(
21982208
changed_lines(curbuf->b_op_start.lnum, 0,
21992209
curbuf->b_op_start.lnum, nr_lines);
22002210

2201-
// put '] mark at last inserted character
2211+
// Put the '] mark on the first byte of the last inserted character.
2212+
// Correct the length for change in indent.
22022213
curbuf->b_op_end.lnum = new_lnum;
2203-
// correct length for change in indent
22042214
col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff;
22052215
if (col > 1)
2206-
curbuf->b_op_end.col = col - 1;
2216+
curbuf->b_op_end.col = col - 1
2217+
- mb_head_off(y_array[y_size - 1],
2218+
y_array[y_size - 1] + col - 1);
22072219
else
22082220
curbuf->b_op_end.col = 0;
22092221

src/testdir/test_put.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,18 @@ func Test_put_above_first_line()
197197
bwipe!
198198
endfunc
199199

200+
func Test_multibyte_op_end_mark()
201+
new
202+
call setline(1, 'тест')
203+
normal viwdp
204+
call assert_equal([0, 1, 7, 0], getpos("'>"))
205+
call assert_equal([0, 1, 7, 0], getpos("']"))
206+
207+
normal Vyp
208+
call assert_equal([0, 1, 2147483647, 0], getpos("'>"))
209+
call assert_equal([0, 2, 7, 0], getpos("']"))
210+
bwipe!
211+
endfunc
212+
200213

201214
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3677,
760762
/**/
761763
3676,
762764
/**/

0 commit comments

Comments
 (0)