patch 9.2.0533: '[ mark moved to end of inserted text after CTRL-R CTRL-P paste

Problem:  After CTRL-R CTRL-P (or CTRL-R CTRL-O) pastes a register
          into Insert mode, a follow-up edit such as backspace makes
          stop_arrow() rewrite Insstart with the post-paste cursor
          position.  As a result the '[ mark points at the end of the
          inserted text instead of its start  (agguser, after 9.2.0384)
Solution: In stop_arrow(), only pull Insstart back when the cursor
          moved above the previous Insstart, so a line-start backspace
          can still save the joined range (#20031) without disturbing
          the start position for inserts that advance the cursor
          (Hirohito Higashi).

related: #20031
fixes:   #20130
closes:  #20322

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Hirohito Higashi
2026-05-25 15:36:30 +00:00
committed by Christian Brabandt
parent e323740b56
commit bc7805323f
3 changed files with 26 additions and 5 deletions
+10 -5
View File
@@ -2512,11 +2512,16 @@ stop_arrow(void)
{
if (u_save_cursor() == OK)
{
// A command or event may have moved the cursor or edited the
// buffer. Update Insstart so that later edits can properly decide
// whether an extra undo entry is needed.
Insstart = curwin->w_cursor;
Insstart_textlen = (colnr_T)linetabsize_str(ml_get_curline());
// A command or event may have moved the cursor before the next
// edit. Pull Insstart back only when the cursor moved above it,
// so that later edits can properly decide whether an extra undo
// entry is needed. Advancing Insstart would mis-place '[ after a
// register paste.
if (LT_POS(curwin->w_cursor, Insstart))
{
Insstart = curwin->w_cursor;
Insstart_textlen = (colnr_T)linetabsize_str(ml_get_curline());
}
ins_need_undo = FALSE;
}
}
+14
View File
@@ -2482,4 +2482,18 @@ func Test_autoindent_no_strip_after_cursorholdi()
bwipe!
endfunc
" Issue #20130: '[ must mark the start of the paste after CTRL-R CTRL-P + edit.
func Test_open_square_mark_after_ctrl_r_ctrl_p_paste()
new
call setline(1, ['a', 'b', 'c', 'd'])
call cursor(4, 1)
call feedkeys("Vggyjo\<C-r>\<C-p>\"\<BS>\<Esc>", 'xt')
call assert_equal(['a', 'b', 'a', 'b', 'c', 'd', 'c', 'd'],
\ getline(1, '$'))
call assert_equal([0, 3, 1, 0], getpos("'["))
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
+2
View File
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
533,
/**/
532,
/**/