mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +00:00
Merge pull request #16818 from zeertzjq/vim-8.2.3454
vim-patch:8.2.{3454,3455,3497,3540,3581,3678}: some "p" and "gp" patches
This commit is contained in:
@@ -8139,6 +8139,7 @@ static void ex_put(exarg_T *eap)
|
|||||||
eap->forceit = TRUE;
|
eap->forceit = TRUE;
|
||||||
}
|
}
|
||||||
curwin->w_cursor.lnum = eap->line2;
|
curwin->w_cursor.lnum = eap->line2;
|
||||||
|
check_cursor_col();
|
||||||
do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1,
|
do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1,
|
||||||
PUT_LINE|PUT_CURSLINE);
|
PUT_LINE|PUT_CURSLINE);
|
||||||
}
|
}
|
||||||
|
@@ -3470,6 +3470,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
curwin->w_cursor.col -= first_byte_off;
|
curwin->w_cursor.col -= first_byte_off;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
linenr_T new_lnum = new_cursor.lnum;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
// Insert at least one line. When y_type is kMTCharWise, break the first
|
// Insert at least one line. When y_type is kMTCharWise, break the first
|
||||||
// line in two.
|
// line in two.
|
||||||
for (cnt = 1; cnt <= count; cnt++) {
|
for (cnt = 1; cnt <= count; cnt++) {
|
||||||
@@ -3486,6 +3489,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
STRCAT(newp, ptr);
|
STRCAT(newp, ptr);
|
||||||
// insert second line
|
// insert second line
|
||||||
ml_append(lnum, newp, (colnr_T)0, false);
|
ml_append(lnum, newp, (colnr_T)0, false);
|
||||||
|
new_lnum++;
|
||||||
xfree(newp);
|
xfree(newp);
|
||||||
|
|
||||||
oldp = ml_get(lnum);
|
oldp = ml_get(lnum);
|
||||||
@@ -3501,10 +3505,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; i < y_size; i++) {
|
for (; i < y_size; i++) {
|
||||||
if ((y_type != kMTCharWise || i < y_size - 1)
|
if ((y_type != kMTCharWise || i < y_size - 1)) {
|
||||||
&& ml_append(lnum, y_array[i], (colnr_T)0, false)
|
if (ml_append(lnum, y_array[i], (colnr_T)0, false) == FAIL) {
|
||||||
== FAIL) {
|
goto error;
|
||||||
goto error;
|
}
|
||||||
|
new_lnum++;
|
||||||
}
|
}
|
||||||
lnum++;
|
lnum++;
|
||||||
++nr_lines;
|
++nr_lines;
|
||||||
@@ -3554,6 +3559,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
extmark_splice(curbuf, (int)new_cursor.lnum-1, col + 1, 0, 0, 0,
|
extmark_splice(curbuf, (int)new_cursor.lnum-1, col + 1, 0, 0, 0,
|
||||||
(int)y_size+1, 0, totsize+2, kExtmarkUndo);
|
(int)y_size+1, 0, totsize+2, kExtmarkUndo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cnt == 1) {
|
||||||
|
new_lnum = lnum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@@ -3581,11 +3590,12 @@ error:
|
|||||||
|
|
||||||
// Put the '] mark on the first byte of the last inserted character.
|
// Put the '] mark on the first byte of the last inserted character.
|
||||||
// Correct the length for change in indent.
|
// Correct the length for change in indent.
|
||||||
curbuf->b_op_end.lnum = lnum;
|
curbuf->b_op_end.lnum = new_lnum;
|
||||||
col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff;
|
len = STRLEN(y_array[y_size - 1]);
|
||||||
|
col = (colnr_T)len - lendiff;
|
||||||
if (col > 1) {
|
if (col > 1) {
|
||||||
curbuf->b_op_end.col = col - 1 - utf_head_off(y_array[y_size - 1],
|
curbuf->b_op_end.col = col - 1 - utf_head_off(y_array[y_size - 1],
|
||||||
y_array[y_size - 1] + col - 1);
|
y_array[y_size - 1] + len - 1);
|
||||||
} else {
|
} else {
|
||||||
curbuf->b_op_end.col = 0;
|
curbuf->b_op_end.col = 0;
|
||||||
}
|
}
|
||||||
@@ -3604,8 +3614,12 @@ error:
|
|||||||
}
|
}
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
} else {
|
} else {
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = new_lnum;
|
||||||
curwin->w_cursor.col = col;
|
curwin->w_cursor.col = col;
|
||||||
|
curbuf->b_op_end = curwin->w_cursor;
|
||||||
|
if (col > 1) {
|
||||||
|
curbuf->b_op_end.col = col - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (y_type == kMTLineWise) {
|
} else if (y_type == kMTLineWise) {
|
||||||
// put cursor on first non-blank in first inserted line
|
// put cursor on first non-blank in first inserted line
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
|
" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
|
||||||
|
|
||||||
|
source check.vim
|
||||||
|
|
||||||
func Test_put_block()
|
func Test_put_block()
|
||||||
new
|
new
|
||||||
call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x')
|
call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x')
|
||||||
@@ -112,6 +114,39 @@ func Test_put_p_indent_visual()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_gp_with_count_leaves_cursor_at_end()
|
||||||
|
new
|
||||||
|
call setline(1, '<---->')
|
||||||
|
call setreg('@', "foo\nbar", 'c')
|
||||||
|
normal 1G3|3gp
|
||||||
|
call assert_equal([0, 4, 4, 0], getpos("."))
|
||||||
|
call assert_equal(['<--foo', 'barfoo', 'barfoo', 'bar-->'], getline(1, '$'))
|
||||||
|
call assert_equal([0, 4, 3, 0], getpos("']"))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_p_with_count_leaves_mark_at_end()
|
||||||
|
new
|
||||||
|
call setline(1, '<---->')
|
||||||
|
call setreg('@', "start\nend", 'c')
|
||||||
|
normal 1G3|3p
|
||||||
|
call assert_equal([0, 1, 4, 0], getpos("."))
|
||||||
|
call assert_equal(['<--start', 'endstart', 'endstart', 'end-->'], getline(1, '$'))
|
||||||
|
call assert_equal([0, 4, 3, 0], getpos("']"))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_put_above_first_line()
|
||||||
|
new
|
||||||
|
let @" = 'text'
|
||||||
|
silent! normal 0o00
|
||||||
|
0put
|
||||||
|
call assert_equal('text', getline(1))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_multibyte_op_end_mark()
|
func Test_multibyte_op_end_mark()
|
||||||
new
|
new
|
||||||
call setline(1, 'тест')
|
call setline(1, 'тест')
|
||||||
|
Reference in New Issue
Block a user