extmark: don't crash in RO buffer.

This commit is contained in:
Björn Linse 2019-11-16 11:05:56 +01:00
parent 6222cca36a
commit ebdf90e7d7
2 changed files with 16 additions and 4 deletions

View File

@ -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;

View File

@ -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()