aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKillTheMule <KillTheMule@users.noreply.github.com>2019-02-24 14:17:30 +0100
committerJustin M. Keyes <justinkz@gmail.com>2019-03-01 20:01:50 +0100
commit018e0d5a19c3f710f41a78bcbb0c6e3e393a5ed8 (patch)
tree2fe98bc8cd85b3984b3e4e0933b79e765917a59e
parent6cd4ff2ab724583acf3a6e582ad55d0561c7bd28 (diff)
downloadrneovim-018e0d5a19c3f710f41a78bcbb0c6e3e393a5ed8.tar.gz
rneovim-018e0d5a19c3f710f41a78bcbb0c6e3e393a5ed8.tar.bz2
rneovim-018e0d5a19c3f710f41a78bcbb0c6e3e393a5ed8.zip
API/buffer-updates: always detach on buf-reload #9643
Independently of the 'undoreload' option and the length of the file. closes #9642 closes #9643
-rw-r--r--src/nvim/buffer.c3
-rw-r--r--src/nvim/ex_cmds.c5
-rw-r--r--test/functional/api/buffer_updates_spec.lua26
3 files changed, 31 insertions, 3 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 7fd4326914..6ae239c9c3 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -591,7 +591,8 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
/* Change directories when the 'acd' option is set. */
do_autochdir();
- // disable buffer updates for the current buffer
+ // Disable buffer-updates for the current buffer.
+ // No need to check `unload_buf`: in that case the function returned above.
buf_updates_unregister_all(buf);
/*
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 97bddb3258..2a5793f0d4 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2476,8 +2476,8 @@ int do_ecmd(
}
set_bufref(&bufref, buf);
if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) {
- /* Save all the text, so that the reload can be undone.
- * Sync first so that this is a separate undo-able action. */
+ // Save all the text, so that the reload can be undone.
+ // Sync first so that this is a separate undo-able action.
u_sync(false);
if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, true)
== FAIL) {
@@ -2491,6 +2491,7 @@ int do_ecmd(
// Tell readfile() not to clear or reload undo info.
readfile_flags = READ_KEEP_UNDO;
} else {
+ buf_updates_unregister_all(curbuf);
buf_freeall(curbuf, 0); // Free all things for buffer.
}
// If autocommands deleted the buffer we were going to re-edit, give
diff --git a/test/functional/api/buffer_updates_spec.lua b/test/functional/api/buffer_updates_spec.lua
index b54d9e1f6e..b894d2facd 100644
--- a/test/functional/api/buffer_updates_spec.lua
+++ b/test/functional/api/buffer_updates_spec.lua
@@ -678,6 +678,32 @@ describe('API: buffer events:', function()
expectn('Hello There', {})
end)
+ it(':edit! (reload) causes detach #9642', function()
+ local b, tick = editoriginal(true, {'AAA', 'BBB'})
+ command('set undoreload=1')
+
+ command('normal! x')
+ tick = tick + 1
+ expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
+
+ command('edit!')
+ expectn('nvim_buf_detach_event', {b})
+ end)
+
+ it(':enew! does not detach hidden buffer', function()
+ local b, tick = editoriginal(true, {'AAA', 'BBB'})
+ local channel = nvim('get_api_info')[1]
+
+ command('set undoreload=1 hidden')
+ command('normal! x')
+ tick = tick + 1
+ expectn('nvim_buf_lines_event', {b, tick, 0, 1, {'AA'}, false})
+
+ command('enew!')
+ eval('rpcnotify('..channel..', "Hello There")')
+ expectn('Hello There', {})
+ end)
+
it('stays attached if the buffer is hidden', function()
local b, tick = editoriginal(true, {'AAA'})
local channel = nvim('get_api_info')[1]