From fec1181ecde75de1754f1d27a7ba7cbf2b9f43d6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 21 Feb 2023 17:43:53 +0800 Subject: test(legacy/prompt_buffer_spec): align script with oldtest more (#22354) --- test/functional/legacy/prompt_buffer_spec.lua | 88 +++++++++++---------------- 1 file changed, 36 insertions(+), 52 deletions(-) (limited to 'test/functional/legacy/prompt_buffer_spec.lua') diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 63338b8dba..602593d632 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -3,7 +3,6 @@ local Screen = require('test.functional.ui.screen') local feed = helpers.feed local source = helpers.source local clear = helpers.clear -local feed_command = helpers.feed_command local poke_eventloop = helpers.poke_eventloop local meths = helpers.meths local eq = helpers.eq @@ -16,64 +15,74 @@ describe('prompt buffer', function() screen = Screen.new(25, 10) screen:attach() source([[ + set laststatus=0 nohidden + func TextEntered(text) if a:text == "exit" + " Reset &modified to allow the buffer to be closed. set nomodified stopinsert close else + " Add the output above the current prompt. call append(line("$") - 1, 'Command: "' . a:text . '"') + " Reset &modified to allow the buffer to be closed. set nomodified call timer_start(20, {id -> TimerFunc(a:text)}) endif endfunc func TimerFunc(text) + " Add the output above the current prompt. call append(line("$") - 1, 'Result: "' . a:text .'"') + " Reset &modified to allow the buffer to be closed. + set nomodified endfunc func SwitchWindows() call timer_start(0, {-> execute("wincmd p", "")}) endfunc - ]]) - feed_command("set noshowmode | set laststatus=0") - feed_command("call setline(1, 'other buffer')") - feed_command("new") - feed_command("set buftype=prompt") - feed_command("call prompt_setcallback(bufnr(''), function('TextEntered'))") - feed_command("eval bufnr('')->prompt_setprompt('cmd: ')") - end) - - after_each(function() - screen:detach() - end) - it('works', function() + call setline(1, "other buffer") + set nomodified + new + set buftype=prompt + call prompt_setcallback(bufnr(''), function("TextEntered")) + eval bufnr("")->prompt_setprompt("cmd: ") + startinsert + ]]) screen:expect([[ - ^ | + cmd: ^ | ~ | ~ | ~ | - [Prompt] | + [Prompt] [+] | other buffer | ~ | ~ | ~ | - | + -- INSERT -- | ]]) - feed("i") + end) + + after_each(function() + screen:detach() + end) + + -- oldtest: Test_prompt_basic() + it('works', function() feed("hello\n") screen:expect([[ cmd: hello | Command: "hello" | Result: "hello" | cmd: ^ | - [Prompt] [+] | + [Prompt] | other buffer | ~ | ~ | ~ | - | + -- INSERT -- | ]]) feed("exit\n") screen:expect([[ @@ -90,20 +99,8 @@ describe('prompt buffer', function() ]]) end) + -- oldtest: Test_prompt_editing() it('editing', function() - screen:expect([[ - ^ | - ~ | - ~ | - ~ | - [Prompt] | - other buffer | - ~ | - ~ | - ~ | - | - ]]) - feed("i") feed("hello") screen:expect([[ cmd: hel^ | @@ -115,7 +112,7 @@ describe('prompt buffer', function() ~ | ~ | ~ | - | + -- INSERT -- | ]]) feed("-") screen:expect([[ @@ -128,7 +125,7 @@ describe('prompt buffer', function() ~ | ~ | ~ | - | + -- INSERT -- | ]]) feed("lz") screen:expect([[ @@ -141,7 +138,7 @@ describe('prompt buffer', function() ~ | ~ | ~ | - | + -- INSERT -- | ]]) feed("x") screen:expect([[ @@ -154,7 +151,7 @@ describe('prompt buffer', function() ~ | ~ | ~ | - | + -- INSERT -- | ]]) feed("exit\n") screen:expect([[ @@ -171,21 +168,8 @@ describe('prompt buffer', function() ]]) end) + -- oldtest: Test_prompt_switch_windows() it('switch windows', function() - feed_command("set showmode") - feed("i") - screen:expect([[ - cmd: ^ | - ~ | - ~ | - ~ | - [Prompt] [+] | - other buffer | - ~ | - ~ | - ~ | - -- INSERT -- | - ]]) feed(":call SwitchWindows()") screen:expect{grid=[[ cmd: | @@ -227,11 +211,11 @@ describe('prompt buffer', function() ]]) end) + -- oldtest: Test_prompt_while_writing_to_hidden_buffer() it('keeps insert mode after aucmd_restbuf in callback', function() source [[ let s:buf = nvim_create_buf(1, 1) call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])}) - startinsert ]] poke_eventloop() eq({ mode = "i", blocking = false }, meths.get_mode()) -- cgit From 10baf89712724b4b95f7c641f2012f051737003c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 3 Apr 2023 08:36:14 +0800 Subject: vim-patch:9.0.1439: start Insert mode when accessing a hidden prompt buffer (#22867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Start Insert mode when accessing a hidden prompt buffer. Solution: Call leaving_window() in aucmd_restbuf(). (Thorben Tröbst, closes vim/vim#12148, closes vim/vim#12147) https://github.com/vim/vim/commit/cde8de034524d00aba4ff4142e658baff511e12d Cherry-pick test_prompt_buffer.vim changes from patch 9.0.0631. Co-authored-by: orbital --- test/functional/legacy/prompt_buffer_spec.lua | 45 ++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'test/functional/legacy/prompt_buffer_spec.lua') diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 602593d632..6c72cde855 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -3,9 +3,11 @@ local Screen = require('test.functional.ui.screen') local feed = helpers.feed local source = helpers.source local clear = helpers.clear +local command = helpers.command local poke_eventloop = helpers.poke_eventloop local meths = helpers.meths local eq = helpers.eq +local neq = helpers.neq describe('prompt buffer', function() local screen @@ -14,9 +16,11 @@ describe('prompt buffer', function() clear() screen = Screen.new(25, 10) screen:attach() - source([[ - set laststatus=0 nohidden + command('set laststatus=0 nohidden') + end) + local function source_script() + source([[ func TextEntered(text) if a:text == "exit" " Reset &modified to allow the buffer to be closed. @@ -63,7 +67,7 @@ describe('prompt buffer', function() ~ | -- INSERT -- | ]]) - end) + end after_each(function() screen:detach() @@ -71,6 +75,7 @@ describe('prompt buffer', function() -- oldtest: Test_prompt_basic() it('works', function() + source_script() feed("hello\n") screen:expect([[ cmd: hello | @@ -101,6 +106,7 @@ describe('prompt buffer', function() -- oldtest: Test_prompt_editing() it('editing', function() + source_script() feed("hello") screen:expect([[ cmd: hel^ | @@ -170,6 +176,7 @@ describe('prompt buffer', function() -- oldtest: Test_prompt_switch_windows() it('switch windows', function() + source_script() feed(":call SwitchWindows()") screen:expect{grid=[[ cmd: | @@ -213,11 +220,41 @@ describe('prompt buffer', function() -- oldtest: Test_prompt_while_writing_to_hidden_buffer() it('keeps insert mode after aucmd_restbuf in callback', function() + source_script() source [[ let s:buf = nvim_create_buf(1, 1) call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])}) ]] poke_eventloop() - eq({ mode = "i", blocking = false }, meths.get_mode()) + eq({ mode = 'i', blocking = false }, meths.get_mode()) + end) + + -- oldtest: Test_prompt_appending_while_hidden() + it('accessing hidden prompt buffer does not start insert mode', function() + local prev_win = meths.get_current_win() + source([[ + new prompt + set buftype=prompt + set bufhidden=hide + + func s:TextEntered(text) + if a:text == 'exit' + close + endif + let g:entered = a:text + endfunc + call prompt_setcallback(bufnr(), function('s:TextEntered')) + + func DoAppend() + call appendbufline('prompt', '$', 'Test') + endfunc + ]]) + feed('asomething') + eq('something', meths.get_var('entered')) + neq(prev_win, meths.get_current_win()) + feed('exit') + eq(prev_win, meths.get_current_win()) + command('call DoAppend()') + eq({ mode = 'n', blocking = false }, meths.get_mode()) end) end) -- cgit From d52cc668c736ef6ca7ee3655a7eb7fe6475afadc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 10 Apr 2023 07:33:26 +0800 Subject: vim-patch:9.0.1443: ending Insert mode when accessing a hidden prompt buffer (#22984) Problem: Ending Insert mode when accessing a hidden prompt buffer. Solution: Don't stop Insert mode when it was active before. (closes vim/vim#12237) https://github.com/vim/vim/commit/05a627c3d4e42a18f76c14828d68ee4747118211 Co-authored-by: Bram Moolenaar --- test/functional/legacy/prompt_buffer_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/legacy/prompt_buffer_spec.lua') diff --git a/test/functional/legacy/prompt_buffer_spec.lua b/test/functional/legacy/prompt_buffer_spec.lua index 6c72cde855..5c3f8a6f8c 100644 --- a/test/functional/legacy/prompt_buffer_spec.lua +++ b/test/functional/legacy/prompt_buffer_spec.lua @@ -247,6 +247,7 @@ describe('prompt buffer', function() func DoAppend() call appendbufline('prompt', '$', 'Test') + return '' endfunc ]]) feed('asomething') @@ -254,7 +255,12 @@ describe('prompt buffer', function() neq(prev_win, meths.get_current_win()) feed('exit') eq(prev_win, meths.get_current_win()) + eq({ mode = 'n', blocking = false }, meths.get_mode()) command('call DoAppend()') eq({ mode = 'n', blocking = false }, meths.get_mode()) + feed('i') + eq({ mode = 'i', blocking = false }, meths.get_mode()) + command('call DoAppend()') + eq({ mode = 'i', blocking = false }, meths.get_mode()) end) end) -- cgit