mirror of
https://github.com/vim/vim.git
synced 2026-05-28 00:21:37 +02:00
patch 9.2.0346: Wrong cursor position when entering command line window
Problem: Wrong cursor position when entering command line window
Solution: Add check_cursor() command to verify the cursor position
(Hirohito Higashi).
When opening the command-line window with CTRL-F after typing a command
that fills the screen width, the cursor was placed past the end of the
line. Add check_cursor() after setting State to MODE_NORMAL so the
cursor is adjusted to the last character.
Also fix the cmdwin prefix character (e.g. ':') being drawn on wrapped
continuation rows. Draw an empty space instead so that the text
alignment is preserved.
closes: #19964
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
efbd482116
commit
c4fe1e958a
+11
-4
@@ -2053,12 +2053,19 @@ win_line(
|
||||
wlv.draw_state = WL_CMDLINE;
|
||||
if (wp == cmdwin_win)
|
||||
{
|
||||
// Draw the cmdline character.
|
||||
wlv.n_extra = 1;
|
||||
wlv.c_extra = cmdwin_type;
|
||||
wlv.c_final = NUL;
|
||||
wlv.char_attr =
|
||||
hl_combine_attr(get_win_attr(wp), HL_ATTR(HLF_AT));
|
||||
if (wlv.row == wlv.startrow)
|
||||
{
|
||||
wlv.c_extra = cmdwin_type;
|
||||
wlv.char_attr = hl_combine_attr(
|
||||
get_win_attr(wp), HL_ATTR(HLF_AT));
|
||||
}
|
||||
else
|
||||
{
|
||||
wlv.c_extra = ' ';
|
||||
wlv.char_attr = get_win_attr(wp);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef FEAT_FOLDING
|
||||
|
||||
@@ -4867,6 +4867,7 @@ open_cmdwin(void)
|
||||
exmode_active = 0;
|
||||
|
||||
State = MODE_NORMAL;
|
||||
check_cursor();
|
||||
setmouse();
|
||||
clear_showcmd();
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
| +0&#ffffff0@39
|
||||
|~+0#4040ff13&| @38
|
||||
|[+1#0000000&|N|o| |N|a|m|e|]| @12|0|,|0|-|1| @9|A|l@1
|
||||
|:+0#4040ff13&|e+0#af5f00255&|c|h|o| +0#0000000&|"+0#e000002&|a@31|"
|
||||
| +0#0000000&|X|Y>Z| @35
|
||||
|~+0#4040ff13&| @38
|
||||
|~| @38
|
||||
|~| @38
|
||||
|~| @38
|
||||
|~| @38
|
||||
|[+3#0000000&|C|o|m@1|a|n|d| |L|i|n|e|]| @7|1|,|4|2| @10|A|l@1
|
||||
| +0&&@39
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|:+0#4040ff13&|s+0#af5f00255&|e|t| +0#0000000&|w+0#e000e06&|i|l|d|m|o|d|e|=+0#af5f00255&|l+0#0000000&|o|n|g|e|s|t|,+0#e000e06&|f+0#0000000&|u|l@1| @48
|
||||
|:+0#4040ff13&|s+0#af5f00255&|e|t| +0#0000000&|w+0#e000e06&|i|l|d|m|o|d|e|=+0#af5f00255&|f+0#0000000&|u|l@1| @56
|
||||
|:+0#4040ff13&|s+0#af5f00255&|i|g|n| +0#0000000&|d|e|f|i|n|e| @62
|
||||
|:+0#4040ff13&|s+0#af5f00255&|i|g|n| +0#0000000&|d|e|f|i|n|e> @62
|
||||
|:+0#4040ff13&|s+0#af5f00255&|i|g|n| +0#0000000&|d|e|f|i|n>e| @62
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|[+3#0000000&|C|o|m@1|a|n|d| |L|i|n|e|]| @60
|
||||
|
||||
@@ -2947,7 +2947,7 @@ func Test_wildmenu_pum()
|
||||
|
||||
" When the popup is open, entering the cmdline window should close the popup
|
||||
call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
|
||||
call WaitForTermCurPosAndLinesToMatch(buf, [6, (strlen(':sign define') + 1)], g:test_timeout, (rows, '^You discovered the command-line window! You can close it with ":q"\.'))
|
||||
call WaitForTermCurPosAndLinesToMatch(buf, [6, strlen(':sign define')], g:test_timeout, (rows, '^You discovered the command-line window! You can close it with ":q"\.'))
|
||||
call WaitFor({buf_ -> {-> term_scrape(buf, 6)->slice(1, 5)->filter({_, v -> v.fg == '#af5f00'})->len() == 4}}(buf), g:test_timeout)
|
||||
call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
|
||||
call term_sendkeys(buf, ":q\<CR>")
|
||||
|
||||
@@ -611,4 +611,38 @@ func Test_cmdwin_showcmd()
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
func Test_cmdwin_cursor_position()
|
||||
" When the cmdline fills the screen width exactly, pressing CTRL-F to open
|
||||
" the cmdwin should place the cursor on the last character, not past it.
|
||||
let cmd = 'echo "' .. repeat('a', &columns - 8) .. '"'
|
||||
call assert_equal(&columns - 1, len(cmd))
|
||||
let g:cmdwin_col = 0
|
||||
let g:cmdwin_line = ''
|
||||
call feedkeys(':' .. cmd .. "\<C-F>" ..
|
||||
\ ":let g:cmdwin_col = col('.')\<CR>" ..
|
||||
\ ":let g:cmdwin_line = getline('.')\<CR>" ..
|
||||
\ ":q\<CR>", 'x!')
|
||||
call assert_equal(len(cmd), g:cmdwin_col)
|
||||
call assert_equal(cmd, g:cmdwin_line)
|
||||
unlet g:cmdwin_col g:cmdwin_line
|
||||
endfunc
|
||||
|
||||
func Test_cmdwin_no_prefix_on_wrapped_line()
|
||||
CheckScreendump
|
||||
|
||||
let lines =<< trim END
|
||||
augroup vimHints | au! | augroup END
|
||||
END
|
||||
call writefile(lines, 'Xcmdwin_wrap', 'D')
|
||||
|
||||
let buf = RunVimInTerminal('-S Xcmdwin_wrap', #{rows: 12, cols: 40})
|
||||
let cmd = 'echo "' .. repeat('a', 40 - 8) .. '"XYZ'
|
||||
call term_sendkeys(buf, ':' .. cmd .. "\<C-F>")
|
||||
call TermWait(buf, 100)
|
||||
call VerifyScreenDump(buf, 'Test_cmdwin_wrap_prefix', {})
|
||||
|
||||
call term_sendkeys(buf, ":q\<CR>")
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
@@ -734,6 +734,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
346,
|
||||
/**/
|
||||
345,
|
||||
/**/
|
||||
|
||||
Reference in New Issue
Block a user