1
0
forked from aniani/vim

patch 9.1.1070: Cannot control cursor positioning of getchar()

Problem:  Cannot control cursor positioning of getchar().
Solution: Add "cursor" flag to {opts}, with possible values "hide",
          "keep" and "msg".

related: #10603
closes: #16569

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-02-02 19:01:01 +01:00
committed by Christian Brabandt
parent 001c26cd61
commit edf0f7db28
6 changed files with 98 additions and 11 deletions

View File

@@ -2628,6 +2628,14 @@ func Test_getchar()
call assert_fails('call getchar(1, 1)', 'E1206:')
call assert_fails('call getcharstr(1, 1)', 'E1206:')
call assert_fails('call getchar(1, #{cursor: "foo"})', 'E475:')
call assert_fails('call getcharstr(1, #{cursor: "foo"})', 'E475:')
call assert_fails('call getchar(1, #{cursor: 0z})', 'E976:')
call assert_fails('call getcharstr(1, #{cursor: 0z})', 'E976:')
call assert_fails('call getchar(1, #{simplify: 0z})', 'E974:')
call assert_fails('call getcharstr(1, #{simplify: 0z})', 'E974:')
call assert_fails('call getchar(1, #{number: []})', 'E745:')
call assert_fails('call getchar(1, #{number: {}})', 'E728:')
call assert_fails('call getcharstr(1, #{number: v:true})', 'E475:')
call assert_fails('call getcharstr(1, #{number: v:false})', 'E475:')
@@ -2646,6 +2654,57 @@ func Test_getchar()
enew!
endfunc
func Test_getchar_cursor_position()
CheckRunVimInTerminal
let lines =<< trim END
call setline(1, ['foobar', 'foobar', 'foobar'])
call cursor(3, 6)
nnoremap <F1> <Cmd>echo 1234<Bar>call getchar()<CR>
nnoremap <F2> <Cmd>call getchar()<CR>
nnoremap <F3> <Cmd>call getchar(-1, {})<CR>
nnoremap <F4> <Cmd>call getchar(-1, #{cursor: 'msg'})<CR>
nnoremap <F5> <Cmd>call getchar(-1, #{cursor: 'keep'})<CR>
nnoremap <F6> <Cmd>call getchar(-1, #{cursor: 'hide'})<CR>
END
call writefile(lines, 'XgetcharCursorPos', 'D')
let buf = RunVimInTerminal('-S XgetcharCursorPos', {'rows': 6})
call WaitForAssert({-> assert_equal([3, 6], term_getcursor(buf)[0:1])})
call term_sendkeys(buf, "\<F1>")
call WaitForAssert({-> assert_equal([6, 5], term_getcursor(buf)[0:1])})
call assert_true(term_getcursor(buf)[2].visible)
call term_sendkeys(buf, 'a')
call WaitForAssert({-> assert_equal([3, 6], term_getcursor(buf)[0:1])})
call assert_true(term_getcursor(buf)[2].visible)
for key in ["\<F2>", "\<F3>", "\<F4>"]
call term_sendkeys(buf, key)
call WaitForAssert({-> assert_equal([6, 1], term_getcursor(buf)[0:1])})
call assert_true(term_getcursor(buf)[2].visible)
call term_sendkeys(buf, 'a')
call WaitForAssert({-> assert_equal([3, 6], term_getcursor(buf)[0:1])})
call assert_true(term_getcursor(buf)[2].visible)
endfor
call term_sendkeys(buf, "\<F5>")
call TermWait(buf, 50)
call assert_equal([3, 6], term_getcursor(buf)[0:1])
call assert_true(term_getcursor(buf)[2].visible)
call term_sendkeys(buf, 'a')
call TermWait(buf, 50)
call assert_equal([3, 6], term_getcursor(buf)[0:1])
call assert_true(term_getcursor(buf)[2].visible)
call term_sendkeys(buf, "\<F6>")
call WaitForAssert({-> assert_false(term_getcursor(buf)[2].visible)})
call term_sendkeys(buf, 'a')
call WaitForAssert({-> assert_true(term_getcursor(buf)[2].visible)})
call assert_equal([3, 6], term_getcursor(buf)[0:1])
call StopVimInTerminal(buf)
endfunc
func Test_libcall_libcallnr()
CheckFeature libcall