fix(messages): inputlist() offers the mouse when it cannot be used (#41280)

Problem:
`inputlist()` advertises "click with the mouse" purely because it
implements click selection, so under the default `'mouse'` of "nvi" it
offers a click that command-line mode never receives.

Solution:
Only offer the mouse when `'mouse'` covers command-line mode, the same
condition `:help inputlist()` already documents.
This commit is contained in:
Barrett Ruth
2026-08-13 18:38:39 -05:00
committed by GitHub
parent faf8345eef
commit fc3f71fb7d
6 changed files with 26 additions and 12 deletions

View File

@@ -17,6 +17,7 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/option_vars.h"
#include "nvim/os/input.h"
#include "nvim/state_defs.h"
#include "nvim/ui.h"
@@ -81,7 +82,7 @@ int prompt_for_input(char *prompt, int hl_id, bool one_key, bool *mouse_used)
char *kmsg = keep_msg ? xstrdup(keep_msg) : NULL;
if (prompt == NULL) {
if (mouse_used != NULL) {
if (mouse_used != NULL && ui_mouse_has(kMouseCommand)) {
prompt = _("Type number and <Enter> or click with the mouse (q or empty cancels): ");
} else {
prompt = _("Type number and <Enter> (q or empty cancels): ");

View File

@@ -163,7 +163,7 @@ describe("preserve and (R)ecover with custom 'directory'", function()
content = { { '' } },
pos = 0,
-- Default vim.ui.select prompt.
prompt = 'Type number and <Enter> or click with the mouse (q or empty cancels): ',
prompt = 'Type number and <Enter> (q or empty cancels): ',
},
},
condition = function()
@@ -189,7 +189,7 @@ describe("preserve and (R)ecover with custom 'directory'", function()
'\n1:.*%.swo',
'\n2:.*%.swp',
'host name:',
vim.pesc('Type number and <Enter> or click with the mouse (q or empty cancels): ^'),
vim.pesc('Type number and <Enter> (q or empty cancels): ^'),
},
none = vim.pesc('{18:^@}'),
})

View File

@@ -1007,7 +1007,7 @@ describe('cmdline redraw', function()
{3: }|
foo |
bar |
Type number and <Enter> or click with the mouse (q or empty cancels): ^ |
Type number and <Enter> (q or empty cancels): ^ |
]])
command('redraw')
screen:expect_unchanged()

View File

@@ -654,7 +654,7 @@ describe('messages2', function()
4 |
5 |
6 [+93] |
Type number and <Enter> or click with the mouse (q or empty cancels): ^ |
Type number and <Enter> (q or empty cancels): ^ |
]]
feed(':call inputlist(range(100))<CR>')
screen:expect(top)
@@ -670,7 +670,7 @@ describe('messages2', function()
5 |
6 |
7 [+92] |
Type number and <Enter> or click with the mouse (q or empty cancels): ^ |
Type number and <Enter> (q or empty cancels): ^ |
]])
feed('<Up>')
screen:expect(top)
@@ -686,7 +686,7 @@ describe('messages2', function()
9 |
10 |
11 [+88] |
Type number and <Enter> or click with the mouse (q or empty cancels): ^ |
Type number and <Enter> (q or empty cancels): ^ |
]])
feed('<PageUp>')
screen:expect(top)
@@ -702,7 +702,7 @@ describe('messages2', function()
97 |
98 |
99 |
Type number and <Enter> or click with the mouse (q or empty cancels): ^ |
Type number and <Enter> (q or empty cancels): ^ |
]])
-- No scrolling beyond end of buffer #36114
feed('<PageDown>')

View File

@@ -407,7 +407,7 @@ describe('ui/ext_messages', function()
content = { { '' } },
pos = 0,
-- Default vim.ui.select uses this prompt.
prompt = 'Type number and <Enter> or click with the mouse (q or empty cancels): ',
prompt = 'Type number and <Enter> (q or empty cancels): ',
},
},
-- Message depends on runtimepath, only test the static text...
@@ -1292,7 +1292,7 @@ stack traceback:
{
content = { { '' } },
pos = 0,
prompt = 'Type number and <Enter> or click with the mouse (q or empty cancels): ',
prompt = 'Type number and <Enter> (q or empty cancels): ',
},
},
messages = {
@@ -1313,7 +1313,7 @@ stack traceback:
{
content = { { '1' } },
pos = 1,
prompt = 'Type number and <Enter> or click with the mouse (q or empty cancels): ',
prompt = 'Type number and <Enter> (q or empty cancels): ',
},
},
})
@@ -1334,7 +1334,7 @@ stack traceback:
{
content = { { '' } },
pos = 0,
prompt = 'Type number and <Enter> or click with the mouse (q or empty cancels): ',
prompt = 'Type number and <Enter> (q or empty cancels): ',
},
},
messages = { { content = { { 'input0\ninput1' } }, kind = 'confirm' } },

View File

@@ -427,6 +427,19 @@ describe('inputdialog()', function()
end)
end)
describe('inputlist()', function()
it("only offers the mouse when 'mouse' applies to cmdline mode", function()
screen:try_resize(75, 5)
feed(':call inputlist(["foo", "bar"])<CR>')
screen:expect({ any = vim.pesc('Type number and <Enter> (q or empty cancels): ') })
feed('q')
command('set mouse=a')
feed(':call inputlist(["foo", "bar"])<CR>')
screen:expect({ any = vim.pesc('Type number and <Enter> or click with the mouse') })
feed('q')
end)
end)
describe('confirm()', function()
it('works', function()
api.nvim_set_option_value('more', false, {}) -- Avoid hit-enter prompt