aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2023-07-27 01:38:23 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2024-01-28 12:29:26 +0000
commitcf140fb25b94c556396fe942a4af3e8db9effa37 (patch)
treead454e6616d049d60b18d11929c16bfb0af52003 /src/nvim/ex_cmds.c
parent2cd76a758b4511748d9482e5af58162a608516b4 (diff)
downloadrneovim-cf140fb25b94c556396fe942a4af3e8db9effa37.tar.gz
rneovim-cf140fb25b94c556396fe942a4af3e8db9effa37.tar.bz2
rneovim-cf140fb25b94c556396fe942a4af3e8db9effa37.zip
vim-patch:9.1.0047: issues with temp curwin/buf while cmdwin is open
Problem: Things that temporarily change/restore curwin/buf (e.g: win_execute, some autocmds) may break assumptions that curwin/buf is the cmdwin when "cmdwin_type != 0", causing issues. Solution: Expose the cmdwin's real win/buf and check that instead. Also try to ensure these variables are NULL if "cmdwin_type == 0", allowing them to be used directly in most cases without checking cmdwin_type. (Sean Dewar) Reset and save `cmdwin_old_curwin` in a similar fashion. Apply suitable changes for API functions and add Lua tests. https://github.com/vim/vim/commit/988f74311c26ea9917e84fbae608de226dba7e5f
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 373ff8feda..41d8e5d914 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2305,10 +2305,19 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
// If the current buffer was empty and has no file name, curbuf
// is returned by buflist_new(), nothing to do here.
if (buf != curbuf) {
+ // Should only be possible to get here if the cmdwin is closed, or
+ // if it's opening and its buffer hasn't been set yet (the new
+ // buffer is for it).
+ assert(cmdwin_buf == NULL);
+
const int save_cmdwin_type = cmdwin_type;
+ win_T *const save_cmdwin_win = cmdwin_win;
+ win_T *const save_cmdwin_old_curwin = cmdwin_old_curwin;
// BufLeave applies to the old buffer.
cmdwin_type = 0;
+ cmdwin_win = NULL;
+ cmdwin_old_curwin = NULL;
// Be careful: The autocommands may delete any buffer and change
// the current buffer.
@@ -2324,7 +2333,11 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum
const bufref_T save_au_new_curbuf = au_new_curbuf;
set_bufref(&au_new_curbuf, buf);
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf);
+
cmdwin_type = save_cmdwin_type;
+ cmdwin_win = save_cmdwin_win;
+ cmdwin_old_curwin = save_cmdwin_old_curwin;
+
if (!bufref_valid(&au_new_curbuf)) {
// New buffer has been deleted.
delbuf_msg(new_name); // Frees new_name.