diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-11-16 12:01:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-16 12:01:53 +0100 |
commit | 18096631b160e136a07cc56bf29fe6a82d277fd5 (patch) | |
tree | 41089d7a998d36e3f955fbdcd46d0bebc229080e /src/nvim/undo.c | |
parent | d79164c9f9ffbb17b82b3a523e217e61f43697be (diff) | |
parent | ebdf90e7d7c97b4355f42e06769e9424c279d695 (diff) | |
download | rneovim-18096631b160e136a07cc56bf29fe6a82d277fd5.tar.gz rneovim-18096631b160e136a07cc56bf29fe6a82d277fd5.tar.bz2 rneovim-18096631b160e136a07cc56bf29fe6a82d277fd5.zip |
Merge pull request #11399 from bfredl/markundo
extmark: do not crash in read-only buffer
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r-- | src/nvim/undo.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c index b00d2d505f..539d42765d 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -225,9 +225,6 @@ int u_save_cursor(void) */ int u_save(linenr_T top, linenr_T bot) { - if (undo_off) - return OK; - if (top >= bot || bot > (curbuf->b_ml.ml_line_count + 1)) { return FAIL; /* rely on caller to do error messages */ } @@ -246,10 +243,7 @@ int u_save(linenr_T top, linenr_T bot) */ int u_savesub(linenr_T lnum) { - if (undo_off) - return OK; - - return u_savecommon(lnum - 1, lnum + 1, lnum + 1, FALSE); + return u_savecommon(lnum - 1, lnum + 1, lnum + 1, false); } /* @@ -260,10 +254,7 @@ int u_savesub(linenr_T lnum) */ int u_inssub(linenr_T lnum) { - if (undo_off) - return OK; - - return u_savecommon(lnum - 1, lnum, lnum + 1, FALSE); + return u_savecommon(lnum - 1, lnum, lnum + 1, false); } /* @@ -275,9 +266,6 @@ int u_inssub(linenr_T lnum) */ int u_savedel(linenr_T lnum, long nlines) { - if (undo_off) - return OK; - return u_savecommon(lnum - 1, lnum + nlines, nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, FALSE); } @@ -2925,9 +2913,6 @@ void u_undoline(void) colnr_T t; char_u *oldp; - if (undo_off) - return; - if (curbuf->b_u_line_ptr == NULL || curbuf->b_u_line_lnum > curbuf->b_ml.ml_line_count) { beep_flush(); @@ -3058,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; |