diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-14 20:46:41 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-14 20:46:41 +0000 |
commit | 7a73252063242e88a6966e9d9ae7ea8beb897518 (patch) | |
tree | 822f0881036f602a6a3aefd79341ac638c415155 /src/normal.c | |
parent | 7d42840033aedf36389208b62e28b4e0b251c199 (diff) | |
download | vim-git-7a73252063242e88a6966e9d9ae7ea8beb897518.tar.gz |
patch 8.2.4567: bracketed paste doesn't work well in Visual linewise modev8.2.4567
Problem: Bracketed paste doesn't work well in Visual linewise mode.
Solution: Handle linewise Visual mode differently. (closes #9947)
Diffstat (limited to 'src/normal.c')
-rw-r--r-- | src/normal.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/normal.c b/src/normal.c index 9376be5ce..e39fb772a 100644 --- a/src/normal.c +++ b/src/normal.c @@ -6880,6 +6880,7 @@ nv_edit(cmdarg_T *cap) { pos_T old_pos = curwin->w_cursor; pos_T old_visual = VIsual; + int old_visual_mode = VIsual_mode; // In Visual mode the selected text is deleted. if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) @@ -6895,11 +6896,32 @@ nv_edit(cmdarg_T *cap) do_pending_operator(cap, 0, FALSE); cap->cmdchar = K_PS; - // When the last char in the line was deleted then append. Detect this - // by checking if the cursor moved to before the Visual area. - if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) - && LT_POS(curwin->w_cursor, old_visual)) - inc_cursor(); + if (*ml_get_cursor() != NUL) + { + if (old_visual_mode == 'V') + { + // In linewise Visual mode insert before the beginning of the + // next line. + // When the last line in the buffer was deleted then create a + // new line, otherwise there is not need to move cursor. + // Detect this by checking if cursor moved above Visual area. + if (curwin->w_cursor.lnum < old_pos.lnum + && curwin->w_cursor.lnum < old_visual.lnum) + { + if (u_save_cursor() == OK) + { + ml_append(curwin->w_cursor.lnum, (char_u *)"", 0, + FALSE); + appended_lines(curwin->w_cursor.lnum++, 1L); + } + } + } + // When the last char in the line was deleted then append. + // Detect this by checking if cursor moved before Visual area. + else if (curwin->w_cursor.col < old_pos.col + && curwin->w_cursor.col < old_visual.col) + inc_cursor(); + } // Insert to replace the deleted text with the pasted text. invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |