vim-patch:8.2.0946: cannot use "q" to cancel a number prompt

Problem:    Cannot use "q" to cancel a number prompt.
Solution:   Recognize "q" instead of ignoring it.
eebd555733
This commit is contained in:
Jan Edmund Lazo
2021-05-20 21:14:59 -04:00
parent 4dadbe64a0
commit 39fdb86832
4 changed files with 24 additions and 9 deletions

View File

@@ -753,8 +753,9 @@ get_number (
skip_redraw = TRUE; /* skip redraw once */ skip_redraw = TRUE; /* skip redraw once */
do_redraw = FALSE; do_redraw = FALSE;
break; break;
} else if (c == CAR || c == NL || c == Ctrl_C || c == ESC) } else if (c == CAR || c == NL || c == Ctrl_C || c == ESC || c == 'q') {
break; break;
}
} }
no_mapping--; no_mapping--;
return n; return n;
@@ -771,11 +772,13 @@ int prompt_for_number(int *mouse_used)
int save_cmdline_row; int save_cmdline_row;
int save_State; int save_State;
/* When using ":silent" assume that <CR> was entered. */ // When using ":silent" assume that <CR> was entered.
if (mouse_used != NULL) if (mouse_used != NULL) {
MSG_PUTS(_("Type number and <Enter> or click with mouse (empty cancels): ")); MSG_PUTS(_("Type number and <Enter> or click with the mouse "
else "(q or empty cancels): "));
MSG_PUTS(_("Type number and <Enter> (empty cancels): ")); } else {
MSG_PUTS(_("Type number and <Enter> (q or empty cancels): "));
}
/* Set the state such that text can be selected/copied/pasted and we still /* Set the state such that text can be selected/copied/pasted and we still
* get mouse events. */ * get mouse events. */

View File

@@ -1067,6 +1067,18 @@ func Test_inputlist()
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx')
call assert_equal(3, c) call assert_equal(3, c)
" CR to cancel
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<cr>", 'tx')
call assert_equal(0, c)
" Esc to cancel
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<Esc>", 'tx')
call assert_equal(0, c)
" q to cancel
call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>q", 'tx')
call assert_equal(0, c)
call assert_fails('call inputlist("")', 'E686:') call assert_fails('call inputlist("")', 'E686:')
endfunc endfunc

View File

@@ -97,7 +97,7 @@ describe('NULL', function()
null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1)
null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items') null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items')
null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]',
'Type number and <Enter> or click with mouse (empty cancels): ', {0, 0}) 'Type number and <Enter> or click with the mouse (q or empty cancels): ', {0, 0})
null_expr_test('is accepted as an empty list by writefile()', null_expr_test('is accepted as an empty list by writefile()',
('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname),
0, {0, {}}) 0, {0, {}})

View File

@@ -811,7 +811,7 @@ describe('ui/ext_messages', function()
{1:~ }| {1:~ }|
{1:^~ }| {1:^~ }|
]], messages={ ]], messages={
{content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with mouse (empty cancels): ' } }, kind = ""} {content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with the mouse (q or empty cancels): ' } }, kind = ""}
}} }}
feed('1') feed('1')
@@ -822,7 +822,7 @@ describe('ui/ext_messages', function()
{1:~ }| {1:~ }|
{1:^~ }| {1:^~ }|
]], messages={ ]], messages={
{content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with mouse (empty cancels): ' } }, kind = ""}, {content = { { 'Change "helllo" to:\n 1 "Hello"\n 2 "Hallo"\n 3 "Helli"\nType number and <Enter> or click with the mouse (q or empty cancels): ' } }, kind = ""},
{ content = { { "1" } }, kind = "" } { content = { { "1" } }, kind = "" }
}} }}