From 48e2a73610ca5639408f79b3d8eebd3e5f57a327 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Thu, 2 Jan 2025 14:51:03 +0100 Subject: feat(ui)!: emit prompt "messages" as cmdline events #31525 Problem: Prompts are emitted as messages events, where cmdline events are more appropriate. The user input is also emitted as message events in fast context, so cannot be displayed with vim.ui_attach(). Solution: Prompt for user input through cmdline prompts. --- test/functional/vimscript/null_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/null_spec.lua b/test/functional/vimscript/null_spec.lua index 9a27239a6d..afd50f7cf9 100644 --- a/test/functional/vimscript/null_spec.lua +++ b/test/functional/vimscript/null_spec.lua @@ -116,7 +116,7 @@ describe('NULL', function() null_expr_test( 'is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', - 'Type number and or click with the mouse (q or empty cancels): ', + '', { 0, 0 } ) null_expr_test( -- cgit From f8680d009741d01e137aeb2232aa7e033cd70d7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Jan 2025 09:27:08 +0800 Subject: vim-patch:9.1.1013: Vim9: Regression caused by patch v9.1.0646 Problem: Vim9: Regression caused by patch v9.1.0646 Solution: Translate the function name before invoking it in call() (Yegappan Lakshmanan) fixes: vim/vim#16430 closes: vim/vim#16445 https://github.com/vim/vim/commit/6289f9159102e0855bedc566636b5e7ca6ced72c N/A patch: vim-patch:8.2.4176: Vim9: cannot use imported function with call() Co-authored-by: Yegappan Lakshmanan --- test/functional/vimscript/ctx_functions_spec.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/ctx_functions_spec.lua b/test/functional/vimscript/ctx_functions_spec.lua index 873e4f820d..85a74c0ab6 100644 --- a/test/functional/vimscript/ctx_functions_spec.lua +++ b/test/functional/vimscript/ctx_functions_spec.lua @@ -188,7 +188,10 @@ describe('context functions', function() function RestoreFuncs() call ctxpop() endfunction + + let g:sid = expand('') ]]) + local sid = api.nvim_get_var('sid') eq('Hello, World!', exec_capture([[call Greet('World')]])) eq( @@ -200,11 +203,11 @@ describe('context functions', function() call('DeleteSFuncs') eq( - 'function Greet, line 1: Vim(call):E117: Unknown function: s:greet', + ('function Greet, line 1: Vim(call):E117: Unknown function: %sgreet'):format(sid), pcall_err(command, [[call Greet('World')]]) ) eq( - 'function GreetAll, line 1: Vim(call):E117: Unknown function: s:greet_all', + ('function GreetAll, line 1: Vim(call):E117: Unknown function: %sgreet_all'):format(sid), pcall_err(command, [[call GreetAll('World', 'One', 'Two', 'Three')]]) ) -- cgit From af069c5c05ad99623345071007ad23da51973601 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 3 Feb 2025 08:09:03 +0800 Subject: vim-patch:9.1.1070: Cannot control cursor positioning of getchar() (#32303) Problem: Cannot control cursor positioning of getchar(). Solution: Add "cursor" flag to {opts}, with possible values "hide", "keep" and "msg". related: vim/vim#10603 closes: vim/vim#16569 https://github.com/vim/vim/commit/edf0f7db28f87611368e158210e58ed30f673098 --- test/functional/vimscript/getchar_spec.lua | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 test/functional/vimscript/getchar_spec.lua (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/getchar_spec.lua b/test/functional/vimscript/getchar_spec.lua new file mode 100644 index 0000000000..1327d741cf --- /dev/null +++ b/test/functional/vimscript/getchar_spec.lua @@ -0,0 +1,92 @@ +local n = require('test.functional.testnvim')() +local Screen = require('test.functional.ui.screen') + +local clear = n.clear +local exec = n.exec +local feed = n.feed +local async_command = n.async_meths.nvim_command + +describe('getchar()', function() + before_each(clear) + + -- oldtest: Test_getchar_cursor_position() + it('cursor positioning', function() + local screen = Screen.new(40, 6) + exec([[ + call setline(1, ['foobar', 'foobar', 'foobar']) + call cursor(3, 6) + ]]) + screen:expect([[ + foobar |*2 + fooba^r | + {1:~ }|*2 + | + ]]) + + -- Default: behaves like "msg" when immediately after printing a message, + -- even if :sleep moved cursor elsewhere. + for _, cmd in ipairs({ + 'echo 1234 | call getchar()', + 'echo 1234 | call getchar(-1, {})', + "echo 1234 | call getchar(-1, #{cursor: 'msg'})", + 'echo 1234 | sleep 1m | call getchar()', + 'echo 1234 | sleep 1m | call getchar(-1, {})', + "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'msg'})", + }) do + async_command(cmd) + screen:expect([[ + foobar |*3 + {1:~ }|*2 + 1234^ | + ]]) + feed('a') + screen:expect([[ + foobar |*2 + fooba^r | + {1:~ }|*2 + 1234 | + ]]) + end + + -- Default: behaves like "keep" when not immediately after printing a message. + for _, cmd in ipairs({ + 'call getchar()', + 'call getchar(-1, {})', + "call getchar(-1, #{cursor: 'keep'})", + "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'keep'})", + }) do + async_command(cmd) + screen:expect_unchanged() + feed('a') + screen:expect_unchanged() + end + + async_command("call getchar(-1, #{cursor: 'msg'})") + screen:expect([[ + foobar |*3 + {1:~ }|*2 + ^1234 | + ]]) + feed('a') + screen:expect([[ + foobar |*2 + fooba^r | + {1:~ }|*2 + 1234 | + ]]) + + async_command("call getchar(-1, #{cursor: 'hide'})") + screen:expect([[ + foobar |*3 + {1:~ }|*2 + 1234 | + ]]) + feed('a') + screen:expect([[ + foobar |*2 + fooba^r | + {1:~ }|*2 + 1234 | + ]]) + end) +end) -- cgit From 3d22293496fc0b8781c3530e8f6a270f1647be93 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Feb 2025 09:31:37 +0800 Subject: test(getchar_spec): fix flakiness (#32320) Problem: getchar_spec may fail when screen:expect_unchanged() doesn't wait long enough. Solution: Add poke_eventloop() before screen:expect_unchanged(). --- test/functional/vimscript/getchar_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/getchar_spec.lua b/test/functional/vimscript/getchar_spec.lua index 1327d741cf..4ecf082f97 100644 --- a/test/functional/vimscript/getchar_spec.lua +++ b/test/functional/vimscript/getchar_spec.lua @@ -5,6 +5,7 @@ local clear = n.clear local exec = n.exec local feed = n.feed local async_command = n.async_meths.nvim_command +local poke_eventloop = n.poke_eventloop describe('getchar()', function() before_each(clear) @@ -56,8 +57,10 @@ describe('getchar()', function() "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'keep'})", }) do async_command(cmd) + poke_eventloop() screen:expect_unchanged() feed('a') + poke_eventloop() screen:expect_unchanged() end -- cgit From aa976f0d932738cb4b4f7cf5bef3d5157c68232d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 5 Feb 2025 11:36:01 +0800 Subject: fix(messages): add a trailing space to inputlist() etc. prompts (#32328) Before #31525 the prompts had a trailing space. Also add a test for #7857. --- test/functional/vimscript/timer_spec.lua | 65 ++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index d1b8bfe5d9..3e4e6de35c 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -94,12 +94,56 @@ describe('timers', function() assert(0 <= diff and diff <= 4, 'expected (0 <= diff <= 4), got: ' .. tostring(diff)) end) + it('are triggered in inputlist() call #7857', function() + async_meths.nvim_exec2( + [[ + call timer_start(5, 'MyHandler', {'repeat': -1}) + let g:val = 0 + let g:n = inputlist(['input0', 'input1']) + ]], + {} + ) + retry(nil, nil, function() + local val = eval('g:val') + ok(val >= 2, '>= 2', tostring(val)) + eq(0, eval("exists('g:n')")) + end) + feed('42') + eq(42, eval('g:n')) + end) + + it('are triggered in confirm() call', function() + api.nvim_ui_attach(80, 24, {}) -- needed for confirm() to work + async_meths.nvim_exec2( + [[ + call timer_start(5, 'MyHandler', {'repeat': -1}) + let g:val = 0 + let g:n = confirm('Are you sure?', "&Yes\n&No\n&Cancel") + ]], + {} + ) + retry(nil, nil, function() + local val = eval('g:val') + ok(val >= 2, '>= 2', tostring(val)) + eq(0, eval("exists('g:n')")) + end) + feed('c') + eq(3, eval('g:n')) + end) + it('are triggered in blocking getchar() call', function() - command("call timer_start(5, 'MyHandler', {'repeat': -1})") - async_meths.nvim_command('let g:val = 0 | let g:c = getchar()') + async_meths.nvim_exec2( + [[ + call timer_start(5, 'MyHandler', {'repeat': -1}) + let g:val = 0 + let g:c = getchar() + ]], + {} + ) retry(nil, nil, function() local val = eval('g:val') ok(val >= 2, '>= 2', tostring(val)) + eq(0, eval("exists('g:c')")) eq(0, eval('getchar(1)')) end) feed('c') @@ -126,39 +170,36 @@ describe('timers', function() redraw endfunc ]]) - async_meths.nvim_command('let g:c2 = getchar()') + async_meths.nvim_command("let g:c2 = getchar(-1, {'cursor': 'msg'})") async_meths.nvim_command( 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})" ) screen:expect([[ - ^ITEM 1 | + ITEM 1 | ITEM 2 | {1:~ }|*3 - | + ^ | ]]) async_meths.nvim_command('let g:cont = 1') screen:expect([[ - ^ITEM 1 | + ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }|*2 - | + ^ | ]]) feed('3') eq(51, eval('g:c2')) - screen:expect { - grid = [[ + screen:expect([[ ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }|*2 | - ]], - unchanged = true, - } + ]]) end) it('can be stopped', function() -- cgit