mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 17:28:23 +00:00
vim-patch:8.1.1373: "[p" in Visual mode puts in wrong line
Problem: "[p" in Visual mode puts in wrong line.
Solution: Call nv_put() instead of duplicating the functionality.
(closes vim/vim#4408)
0ab190c057
This commit is contained in:
@@ -5638,44 +5638,7 @@ static void nv_brackets(cmdarg_T *cap)
|
|||||||
* "[p", "[P", "]P" and "]p": put with indent adjustment
|
* "[p", "[P", "]P" and "]p": put with indent adjustment
|
||||||
*/
|
*/
|
||||||
else if (cap->nchar == 'p' || cap->nchar == 'P') {
|
else if (cap->nchar == 'p' || cap->nchar == 'P') {
|
||||||
if (!checkclearop(cap->oap)) {
|
nv_put_opt(cap, true);
|
||||||
int dir = (cap->cmdchar == ']' && cap->nchar == 'p') ? FORWARD : BACKWARD;
|
|
||||||
int regname = cap->oap->regname;
|
|
||||||
int was_visual = VIsual_active;
|
|
||||||
linenr_T line_count = curbuf->b_ml.ml_line_count;
|
|
||||||
pos_T start, end;
|
|
||||||
|
|
||||||
if (VIsual_active) {
|
|
||||||
start = ltoreq(VIsual, curwin->w_cursor) ? VIsual : curwin->w_cursor;
|
|
||||||
end = equalpos(start, VIsual) ? curwin->w_cursor : VIsual;
|
|
||||||
curwin->w_cursor = (dir == BACKWARD ? start : end);
|
|
||||||
}
|
|
||||||
prep_redo_cmd(cap);
|
|
||||||
do_put(regname, NULL, dir, cap->count1, PUT_FIXINDENT);
|
|
||||||
if (was_visual) {
|
|
||||||
VIsual = start;
|
|
||||||
curwin->w_cursor = end;
|
|
||||||
if (dir == BACKWARD) {
|
|
||||||
/* adjust lines */
|
|
||||||
VIsual.lnum += curbuf->b_ml.ml_line_count - line_count;
|
|
||||||
curwin->w_cursor.lnum += curbuf->b_ml.ml_line_count - line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIsual_active = true;
|
|
||||||
if (VIsual_mode == 'V') {
|
|
||||||
/* delete visually selected lines */
|
|
||||||
cap->cmdchar = 'd';
|
|
||||||
cap->nchar = NUL;
|
|
||||||
cap->oap->regname = regname;
|
|
||||||
nv_operator(cap);
|
|
||||||
do_pending_operator(cap, 0, false);
|
|
||||||
}
|
|
||||||
if (VIsual_active) {
|
|
||||||
end_visual_mode();
|
|
||||||
redraw_later(SOME_VALID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* "['", "[`", "]'" and "]`": jump to next mark
|
* "['", "[`", "]'" and "]`": jump to next mark
|
||||||
@@ -7798,6 +7761,13 @@ static void nv_join(cmdarg_T *cap)
|
|||||||
* "P", "gP", "p" and "gp" commands.
|
* "P", "gP", "p" and "gp" commands.
|
||||||
*/
|
*/
|
||||||
static void nv_put(cmdarg_T *cap)
|
static void nv_put(cmdarg_T *cap)
|
||||||
|
{
|
||||||
|
nv_put_opt(cap, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "P", "gP", "p" and "gp" commands.
|
||||||
|
// "fix_indent" is true for "[p", "[P", "]p" and "]P".
|
||||||
|
static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
|
||||||
{
|
{
|
||||||
int regname = 0;
|
int regname = 0;
|
||||||
yankreg_T *savereg = NULL;
|
yankreg_T *savereg = NULL;
|
||||||
@@ -7815,9 +7785,15 @@ static void nv_put(cmdarg_T *cap)
|
|||||||
} else
|
} else
|
||||||
clearopbeep(cap->oap);
|
clearopbeep(cap->oap);
|
||||||
} else {
|
} else {
|
||||||
dir = (cap->cmdchar == 'P'
|
if (fix_indent) {
|
||||||
|| (cap->cmdchar == 'g' && cap->nchar == 'P'))
|
dir = (cap->cmdchar == ']' && cap->nchar == 'p')
|
||||||
? BACKWARD : FORWARD;
|
? FORWARD : BACKWARD;
|
||||||
|
flags |= PUT_FIXINDENT;
|
||||||
|
} else {
|
||||||
|
dir = (cap->cmdchar == 'P'
|
||||||
|
|| (cap->cmdchar == 'g' && cap->nchar == 'P'))
|
||||||
|
? BACKWARD : FORWARD;
|
||||||
|
}
|
||||||
prep_redo_cmd(cap);
|
prep_redo_cmd(cap);
|
||||||
if (cap->cmdchar == 'g')
|
if (cap->cmdchar == 'g')
|
||||||
flags |= PUT_CURSEND;
|
flags |= PUT_CURSEND;
|
||||||
|
@@ -104,3 +104,15 @@ func Test_put_p_errmsg_nodup()
|
|||||||
delfunction Capture_p_error
|
delfunction Capture_p_error
|
||||||
bwipeout!
|
bwipeout!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_put_p_indent_visual()
|
||||||
|
new
|
||||||
|
call setline(1, ['select this text', 'select that text'])
|
||||||
|
" yank "that" from the second line
|
||||||
|
normal 2Gwvey
|
||||||
|
" select "this" in the first line and put
|
||||||
|
normal k0wve[p
|
||||||
|
call assert_equal('select that text', getline(1))
|
||||||
|
call assert_equal('select that text', getline(2))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
Reference in New Issue
Block a user