diff options
-rw-r--r-- | src/nvim/undo.c | 14 | ||||
-rw-r--r-- | test/functional/api/mark_extended_spec.lua | 6 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c index b36d1ac3ec..539d42765d 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -243,7 +243,7 @@ int u_save(linenr_T top, linenr_T bot) */ int u_savesub(linenr_T lnum) { - return u_savecommon(lnum - 1, lnum + 1, lnum + 1, FALSE); + return u_savecommon(lnum - 1, lnum + 1, lnum + 1, false); } /* @@ -254,7 +254,7 @@ int u_savesub(linenr_T lnum) */ int u_inssub(linenr_T lnum) { - return u_savecommon(lnum - 1, lnum, lnum + 1, FALSE); + return u_savecommon(lnum - 1, lnum, lnum + 1, false); } /* @@ -3043,8 +3043,14 @@ u_header_T *u_force_get_undo_header(buf_T *buf) } // Create the first undo header for the buffer if (!uhp) { - // TODO(timeyyy): there would be a better way to do this! - u_save_cursor(); + // Undo is normally invoked in change code, which already has swapped + // curbuf. + buf_T *save_curbuf = curbuf; + curbuf = buf; + // Args are tricky: this means replace empty range by empty range.. + u_savecommon(0, 1, 1, true); + curbuf = save_curbuf; + uhp = buf->b_u_curhead; if (!uhp) { uhp = buf->b_u_newhead; diff --git a/test/functional/api/mark_extended_spec.lua b/test/functional/api/mark_extended_spec.lua index a5d68c6b9f..76db9f9d81 100644 --- a/test/functional/api/mark_extended_spec.lua +++ b/test/functional/api/mark_extended_spec.lua @@ -1262,6 +1262,12 @@ describe('Extmarks buffer api', function() check_undo_redo(ns, marks[1], 3, 4, 2, 6) end) + it('in read-only buffer', function() + command("view! runtime/doc/help.txt") + eq(true, curbufmeths.get_option('ro')) + local id = set_extmark(ns, 0, 0, 2) + eq({{id, 0, 2}}, get_extmarks(ns,0, -1)) + end) end) describe('Extmarks buffer api with many marks', function() |