From fee7d6fba4a940bdc76661fb06eaa91e24149b51 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 1/6] vim-patch:8.2.3454: using a count with "gp" leave cursor in wrong position Problem: Using a count with "gp" leave cursor in wrong position. (Naohiro Ono) Solution: Count the inserted lines. (closes vim/vim#8899) https://github.com/vim/vim/commit/23003e51e18371afda4420d9e171a3dcba5a31cc --- src/nvim/ops.c | 18 +++++++++++++----- src/nvim/testdir/test_put.vim | 10 ++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 83a7c31991..52164f6c38 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3472,6 +3472,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor.col -= first_byte_off; } } else { + linenr_T new_lnum = new_cursor.lnum; + // Insert at least one line. When y_type is kMTCharWise, break the first // line in two. for (cnt = 1; cnt <= count; cnt++) { @@ -3488,6 +3490,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) STRCAT(newp, ptr); // insert second line ml_append(lnum, newp, (colnr_T)0, false); + new_lnum++; xfree(newp); oldp = ml_get(lnum); @@ -3503,10 +3506,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } for (; i < y_size; i++) { - if ((y_type != kMTCharWise || i < y_size - 1) - && ml_append(lnum, y_array[i], (colnr_T)0, false) - == FAIL) { - goto error; + if ((y_type != kMTCharWise || i < y_size - 1)) { + if (ml_append(lnum, y_array[i], (colnr_T)0, false) == FAIL) { + goto error; + } + new_lnum++; } lnum++; ++nr_lines; @@ -3556,6 +3560,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, (int)y_size+1, 0, totsize+2, kExtmarkUndo); } + + if (cnt == 1) { + new_lnum = lnum; + } } error: @@ -3606,7 +3614,7 @@ error: } curwin->w_cursor.col = 0; } else { - curwin->w_cursor.lnum = lnum; + curwin->w_cursor.lnum = new_lnum; curwin->w_cursor.col = col; } } else if (y_type == kMTLineWise) { diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 440717eaa8..aceac58493 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -112,6 +112,16 @@ func Test_put_p_indent_visual() bwipe! endfunc +func Test_gp_with_count_leaves_cursor_at_end() + new + call setline(1, '<---->') + call setreg('@', "foo\nbar", 'c') + exe "normal 1G3|3gpix\" + call assert_equal(['<--foo', 'barfoo', 'barfoo', 'barx-->'], getline(1, '$')) + + bwipe! +endfunc + func Test_multibyte_op_end_mark() new call setline(1, 'тест') From 7812c6830cb8a600c33eec1854c97ac31e4e03fb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 2/6] vim-patch:8.2.3455: using a count with "gp" leaves '] in wrong position Problem: Using a count with "gp" leaves '] in wrong position. (Naohiro Ono) Solution: Correct the mark position. (closes vim/vim#8899) https://github.com/vim/vim/commit/56858e4ed4e338e15821767b8303b06099e40384 --- src/nvim/ops.c | 4 ++++ src/nvim/testdir/test_put.vim | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 52164f6c38..52c55c8de3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3616,6 +3616,10 @@ error: } else { curwin->w_cursor.lnum = new_lnum; 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) { // put cursor on first non-blank in first inserted line diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index aceac58493..3b6b2e0e0d 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -116,8 +116,10 @@ func Test_gp_with_count_leaves_cursor_at_end() new call setline(1, '<---->') call setreg('@', "foo\nbar", 'c') - exe "normal 1G3|3gpix\" - call assert_equal(['<--foo', 'barfoo', 'barfoo', 'barx-->'], getline(1, '$')) + 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 From 5228850749903c2a19984012ae57ae3960ce87cf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 3/6] vim-patch:8.2.3497: put test fails when run by itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Put test fails when run by itself. Solution: Source check.vim. (Dominique Pellé, closes vim/vim#8990) https://github.com/vim/vim/commit/a9173d06f7ca320fc84f4ffa993861d21710bc41 --- src/nvim/testdir/test_put.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 3b6b2e0e0d..45c9ec9ba5 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -1,5 +1,7 @@ " Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc. +source check.vim + func Test_put_block() new call feedkeys("i\u2500\x\", 'x') From 436a470ef52e60e0a5c553aab53adbc216e650a1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 4/6] vim-patch:8.2.3540: the mark '] is wrong after put with a count Problem: The mark '] is wrong after put with a count. (Naohiro Ono) Solution: Use the right line number. (closes vim/vim#8956) https://github.com/vim/vim/commit/f47ebf1e1a0a6473b10fb4c92c9c6427aab4dc91 --- src/nvim/ops.c | 2 +- src/nvim/testdir/test_put.vim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 52c55c8de3..c29668f541 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3591,7 +3591,7 @@ error: // Put the '] mark on the first byte of the last inserted character. // 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; if (col > 1) { curbuf->b_op_end.col = col - 1 - utf_head_off(y_array[y_size - 1], diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 45c9ec9ba5..4b708fc6a1 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -126,6 +126,18 @@ func Test_gp_with_count_leaves_cursor_at_end() 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_multibyte_op_end_mark() new call setline(1, 'тест') From 6f04d3f3ef5eb45c224dabc64373783de9d3f721 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 5/6] vim-patch:8.2.3581: reading character past end of line Problem: Reading character past end of line. Solution: Correct the cursor column. https://github.com/vim/vim/commit/0b5b06cb4777d1401fdf83e7d48d287662236e7e --- src/nvim/ex_docmd.c | 1 + src/nvim/testdir/test_put.vim | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index c30d58a8eb..43c0d1d0a2 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8133,6 +8133,7 @@ static void ex_put(exarg_T *eap) eap->forceit = TRUE; } curwin->w_cursor.lnum = eap->line2; + check_cursor_col(); do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1, PUT_LINE|PUT_CURSLINE); } diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 4b708fc6a1..ed76709a56 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -138,6 +138,15 @@ func Test_p_with_count_leaves_mark_at_end() 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() new call setline(1, 'тест') From 3adc3fc540ada79860d90b48b66a1e967421aabf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Jan 2022 06:05:39 +0800 Subject: [PATCH 6/6] vim-patch:8.2.3678: illegal memory access Problem: Illegal memory access. Solution: Ignore changed indent when computing byte offset. https://github.com/vim/vim/commit/85be8563fe5aff686e9e30d6afff401ccd976f2a --- src/nvim/ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c29668f541..3a2851f84f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3473,6 +3473,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } } else { linenr_T new_lnum = new_cursor.lnum; + size_t len; // Insert at least one line. When y_type is kMTCharWise, break the first // line in two. @@ -3592,10 +3593,11 @@ error: // 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; - 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) { 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 { curbuf->b_op_end.col = 0; }