diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-08-17 00:53:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 00:53:10 +0100 |
commit | 22d9338afceae5f8ef3845f152dea07a19d512d1 (patch) | |
tree | cf1d8d437fff51efdf1565f4fbe0a40e72e6ee62 | |
parent | e928161bde262c238f79bc0fd84e60178ff6a321 (diff) | |
download | rneovim-22d9338afceae5f8ef3845f152dea07a19d512d1.tar.gz rneovim-22d9338afceae5f8ef3845f152dea07a19d512d1.tar.bz2 rneovim-22d9338afceae5f8ef3845f152dea07a19d512d1.zip |
fix(api): disallow win_set_buf from changing cmdwin's old curbuf (#24745)
A command typed in the cmdwin and executed with `<CR>` is expected to be
executed in the context of the old curwin/buf, so it shouldn't be changed.
-rw-r--r-- | src/nvim/api/window.c | 2 | ||||
-rw-r--r-- | test/functional/api/window_spec.lua | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f74071a002..001797add5 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -58,7 +58,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) if (!win || !buf) { return; } - if (cmdwin_type != 0 && (win == curwin || buf == curbuf)) { + if (cmdwin_type != 0 && (win == curwin || win == cmdwin_old_curwin || buf == curbuf)) { api_set_error(err, kErrorTypeException, "%s", e_cmdwin); return; } diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 00896a97d8..44d4470337 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -44,8 +44,9 @@ describe('API/win', function() eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf'))) end) - it('disallowed in cmdwin if win=curwin or buf=curbuf', function() + it('disallowed in cmdwin if win={old_}curwin or buf=curbuf', function() local new_buf = meths.create_buf(true, true) + local old_win = meths.get_current_win() local new_win = meths.open_win(new_buf, false, { relative='editor', row=10, col=10, width=50, height=10, }) @@ -53,6 +54,8 @@ describe('API/win', function() eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', pcall_err(meths.win_set_buf, 0, new_buf)) eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', + pcall_err(meths.win_set_buf, old_win, new_buf)) + eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits', pcall_err(meths.win_set_buf, new_win, 0)) local next_buf = meths.create_buf(true, true) |