diff options
-rw-r--r-- | src/nvim/ops.c | 25 | ||||
-rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 24 |
2 files changed, 42 insertions, 7 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 1f55d2c315..92d026465f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1544,15 +1544,19 @@ int op_delete(oparg_T *oap) oap->line_count = 0; // no lines deleted } else if (oap->motion_type == kMTLineWise) { if (oap->op_type == OP_CHANGE) { - /* Delete the lines except the first one. Temporarily move the - * cursor to the next line. Save the current line number, if the - * last line is deleted it may be changed. - */ + // Delete the lines except the first one. Temporarily move the + // cursor to the next line. Save the current line number, if the + // last line is deleted it may be changed. + if (oap->line_count > 1) { lnum = curwin->w_cursor.lnum; ++curwin->w_cursor.lnum; del_lines(oap->line_count - 1, TRUE); curwin->w_cursor.lnum = lnum; + + extmark_adjust(curbuf, curwin->w_cursor.lnum, + curwin->w_cursor.lnum + oap->line_count - 1, + MAXLNUM, 0, kExtmarkUndo); } if (u_save_cursor() == FAIL) return FAIL; @@ -1561,9 +1565,16 @@ int op_delete(oparg_T *oap) did_ai = true; // delete the indent when ESC hit ai_col = curwin->w_cursor.col; } else - beginline(0); /* cursor in column 0 */ - truncate_line(FALSE); /* delete the rest of the line */ - /* leave cursor past last char in line */ + beginline(0); // cursor in column 0 + + int old_len = (int)STRLEN(ml_get(curwin->w_cursor.lnum)); + truncate_line(FALSE); // delete the rest of the line + + extmark_splice_cols(curbuf, + (int)curwin->w_cursor.lnum, curwin->w_cursor.col, + old_len - curwin->w_cursor.col, 0, kExtmarkUndo); + + // leave cursor past last char in line if (oap->line_count > 1) u_clearline(); /* "U" command not possible after "2cc" */ } else { diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index ac5d25bdab..6b62768470 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -289,6 +289,12 @@ describe('lua: nvim_buf_attach on_bytes', function() if verify then for _, event in ipairs(events) do + for _, elem in ipairs(event) do + if type(elem) == "number" and elem < 0 then + fail(string.format("Received event has negative values")) + end + end + if event[1] == verify_name and event[2] == "bytes" then local _, _, _, _, _, _, start_byte, _, _, old_byte, _, _, new_byte = unpack(event) local before = string.sub(shadowbytes, 1, start_byte) @@ -411,6 +417,24 @@ describe('lua: nvim_buf_attach on_bytes', function() { "test1", "bytes", 1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; } end) + + it("changing lines", function() + local check_events = setup_eventcheck(verify, origlines) + + feed "cc" + check_events { + { "test1", "bytes", 1, 4, 1, 0, 1, 0, 15, 15, 0, 0, 0 }; + } + + feed "<ESC>" + check_events {} + + feed "c3j" + check_events { + { "test1", "bytes", 1, 4, 1, 0, 1, 3, 0, 48, 0, 0, 0 }; + { "test1", "bytes", 1, 5, 0, 0, 0, 4, 0, 0, 4, 0, 51 }; + } + end) end describe('(with verify) handles', function() |