aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-11-16 12:01:53 +0100
committerGitHub <noreply@github.com>2019-11-16 12:01:53 +0100
commit18096631b160e136a07cc56bf29fe6a82d277fd5 (patch)
tree41089d7a998d36e3f955fbdcd46d0bebc229080e /src
parentd79164c9f9ffbb17b82b3a523e217e61f43697be (diff)
parentebdf90e7d7c97b4355f42e06769e9424c279d695 (diff)
downloadrneovim-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')
-rw-r--r--src/nvim/getchar.c1
-rw-r--r--src/nvim/globals.h1
-rw-r--r--src/nvim/undo.c29
3 files changed, 10 insertions, 21 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 399f0671b4..c038977127 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -2409,7 +2409,6 @@ int inchar(
did_outofmem_msg = FALSE; /* display out of memory message (again) */
did_swapwrite_msg = FALSE; /* display swap file write error again */
}
- undo_off = FALSE; /* restart undo now */
// Get a character from a script file if there is one.
// If interrupted: Stop reading script files, close them all.
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index c3d1a4d40b..227119bcee 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -768,7 +768,6 @@ EXTERN int did_outofmem_msg INIT(= false);
// set after out of memory msg
EXTERN int did_swapwrite_msg INIT(= false);
// set after swap write error msg
-EXTERN int undo_off INIT(= false); // undo switched off for now
EXTERN int global_busy INIT(= 0); // set when :global is executing
EXTERN int listcmd_busy INIT(= false); // set when :argdo, :windo or
// :bufdo is executing
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;