summaryrefslogtreecommitdiff
path: root/src/register.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-11-25 19:31:15 +0000
committerBram Moolenaar <Bram@vim.org>2021-11-25 19:31:15 +0000
commit4d07253a485819b3a9fd923d263e722ea2109c12 (patch)
tree9174bc37493c986aa5cb7dfca539ce518fdb5379 /src/register.c
parent309ce251897512d42da2b0df0ff100dc303e688a (diff)
downloadvim-git-4d07253a485819b3a9fd923d263e722ea2109c12.tar.gz
patch 8.2.3677: after a put the '] mark is on the last bytev8.2.3677
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)
Diffstat (limited to 'src/register.c')
-rw-r--r--src/register.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/register.c b/src/register.c
index 268c839f7..00b8b4bb3 100644
--- a/src/register.c
+++ b/src/register.c
@@ -2004,6 +2004,7 @@ do_put(
{
linenr_T end_lnum = 0; // init for gcc
linenr_T start_lnum = lnum;
+ int first_byte_off = 0;
if (VIsual_active)
{
@@ -2065,6 +2066,10 @@ do_put(
}
STRMOVE(ptr, oldp + col);
ml_replace(lnum, newp, FALSE);
+
+ // compute the byte offset for the last character
+ first_byte_off = mb_head_off(newp, ptr - 1);
+
// Place cursor on last putted char.
if (lnum == curwin->w_cursor.lnum)
{
@@ -2080,10 +2085,15 @@ do_put(
lnum--;
}
+ // put '] at the first byte of the last character
curbuf->b_op_end = curwin->w_cursor;
+ curbuf->b_op_end.col -= first_byte_off;
+
// For "CTRL-O p" in Insert mode, put cursor after last char
if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND)))
++curwin->w_cursor.col;
+ else
+ curwin->w_cursor.col -= first_byte_off;
changed_bytes(lnum, col);
}
else
@@ -2198,12 +2208,14 @@ error:
changed_lines(curbuf->b_op_start.lnum, 0,
curbuf->b_op_start.lnum, nr_lines);
- // put '] mark at last inserted character
+ // Put the '] mark on the first byte of the last inserted character.
+ // Correct the length for change in indent.
curbuf->b_op_end.lnum = new_lnum;
- // correct length for change in indent
col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff;
if (col > 1)
- curbuf->b_op_end.col = col - 1;
+ curbuf->b_op_end.col = col - 1
+ - mb_head_off(y_array[y_size - 1],
+ y_array[y_size - 1] + col - 1);
else
curbuf->b_op_end.col = 0;