aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-11-25 22:53:14 +0000
committerSean Dewar <seandewar@users.noreply.github.com>2021-12-07 11:34:28 +0000
commit361f548437a0a9b620db620356fdd405d24a7b34 (patch)
tree5c1f37e6bf9c6dac63cebb4a87d99183f7799e17
parent0f792b284fbb924d46020a31162a7660fa6dc077 (diff)
downloadrneovim-361f548437a0a9b620db620356fdd405d24a7b34.tar.gz
rneovim-361f548437a0a9b620db620356fdd405d24a7b34.tar.bz2
rneovim-361f548437a0a9b620db620356fdd405d24a7b34.zip
vim-patch:8.2.3671: restarting Insert mode in prompt buffer too often
Problem: Restarting Insert mode in prompt buffer too often when a callback switches windows and comes back. (Sean Dewar) Solution: Do not set "restart_edit" when already in Insert mode. https://github.com/vim/vim/commit/34c20ff85b87be587ea5d0398812441b502ee6a5 As Test_prompt_switch_windows is skipped, implement it in prompt_buffer_spec. Replace the 50ms term_wait calls with poke_eventloop (test seems to work anyway without them, so maybe they're not required?) The new test does include a duplicate screen test that may generate a "screen test succeeded immediately" warning, but this is done to match the Vim test.
-rw-r--r--src/nvim/testdir/test_prompt_buffer.vim26
-rw-r--r--src/nvim/window.c6
-rw-r--r--test/functional/legacy/prompt_buffer_spec.lua49
3 files changed, 79 insertions, 2 deletions
diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim
index 4212dcb36e..8f94a8572b 100644
--- a/src/nvim/testdir/test_prompt_buffer.vim
+++ b/src/nvim/testdir/test_prompt_buffer.vim
@@ -41,6 +41,10 @@ func WriteScript(name)
\ ' set nomodified',
\ 'endfunc',
\ '',
+ \ 'func SwitchWindows()',
+ \ ' call timer_start(0, {-> execute("wincmd p|wincmd p", "")})',
+ \ 'endfunc',
+ \ '',
\ 'call setline(1, "other buffer")',
\ 'set nomodified',
\ 'new',
@@ -103,6 +107,28 @@ func Test_prompt_editing()
call delete(scriptName)
endfunc
+func Test_prompt_switch_windows()
+ throw 'skipped: TODO'
+ call CanTestPromptBuffer()
+ let scriptName = 'XpromptSwitchWindows'
+ call WriteScript(scriptName)
+
+ let buf = RunVimInTerminal('-S ' . scriptName, {'rows': 12})
+ call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))})
+ call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 12))})
+
+ call term_sendkeys(buf, "\<C-O>:call SwitchWindows()\<CR>")
+ call term_wait(buf, 50)
+ call WaitForAssert({-> assert_match('-- INSERT --', term_getline(buf, 12))})
+
+ call term_sendkeys(buf, "\<Esc>")
+ call term_wait(buf, 50)
+ call WaitForAssert({-> assert_match('^ *$', term_getline(buf, 12))})
+
+ call StopVimInTerminal(buf)
+ call delete(scriptName)
+endfunc
+
func Test_prompt_garbage_collect()
func MyPromptCallback(x, text)
" NOP
diff --git a/src/nvim/window.c b/src/nvim/window.c
index e0ba4b72f3..be963d8374 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -2271,8 +2271,10 @@ void entering_window(win_T *const win)
}
// When entering the prompt window restart Insert mode if we were in Insert
- // mode when we left it.
- restart_edit = win->w_buffer->b_prompt_insert;
+ // mode when we left it and not already in Insert mode.
+ if ((State & INSERT) == 0) {
+ restart_edit = win->w_buffer->b_prompt_insert;
+ }
}
/// Closes all windows for buffer `buf`.
diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua
index e689c29dfd..47eca19de3 100644
--- a/test/functional/legacy/prompt_buffer_spec.lua
+++ b/test/functional/legacy/prompt_buffer_spec.lua
@@ -31,6 +31,10 @@ describe('prompt buffer', function()
func TimerFunc(text)
call append(line("$") - 1, 'Result: "' . a:text .'"')
endfunc
+
+ func SwitchWindows()
+ call timer_start(0, {-> execute("wincmd p|wincmd p", "")})
+ endfunc
]])
feed_command("set noshowmode | set laststatus=0")
feed_command("call setline(1, 'other buffer')")
@@ -167,6 +171,51 @@ describe('prompt buffer', function()
]])
end)
+ it('switch windows', function()
+ feed_command("set showmode")
+ feed("i")
+ screen:expect([[
+ cmd: ^ |
+ ~ |
+ ~ |
+ ~ |
+ [Prompt] [+] |
+ other buffer |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ feed("<C-O>:call SwitchWindows()<CR>")
+ poke_eventloop()
+ screen:expect([[
+ cmd: ^ |
+ ~ |
+ ~ |
+ ~ |
+ [Prompt] [+] |
+ other buffer |
+ ~ |
+ ~ |
+ ~ |
+ -- INSERT -- |
+ ]])
+ feed("<Esc>")
+ poke_eventloop()
+ screen:expect([[
+ cmd:^ |
+ ~ |
+ ~ |
+ ~ |
+ [Prompt] [+] |
+ other buffer |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]])
+ end)
+
it('keeps insert mode after aucmd_restbuf in callback', function()
source [[
let s:buf = nvim_create_buf(1, 1)