commit 5f9f7064622cda25ac5d34f8b5a0c10248181489
parent c47a69c1a6c2feabcd13f428adb6b78d7d385d46
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 7 Aug 2025 12:22:01 +0800
fix(ui): check for cmdline mode properly (#35202)
Diffstat:
8 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
@@ -270,7 +270,7 @@ void screenclear(void)
/// to be re-emitted: avoid clearing the prompt from the message grid.
static bool cmdline_number_prompt(void)
{
- return !ui_has(kUIMessages) && State == MODE_CMDLINE && get_cmdline_info()->mouse_used != NULL;
+ return !ui_has(kUIMessages) && (State & MODE_CMDLINE) && get_cmdline_info()->mouse_used != NULL;
}
/// Set dimensions of the Nvim application "screen".
@@ -372,8 +372,8 @@ void screen_resize(int width, int height)
// - in Ex mode, don't redraw anything.
// - Otherwise, redraw right now, and position the cursor.
if (State == MODE_ASKMORE || State == MODE_EXTERNCMD || exmode_active
- || (State == MODE_CMDLINE && get_cmdline_info()->one_key)) {
- if (State == MODE_CMDLINE) {
+ || ((State & MODE_CMDLINE) && get_cmdline_info()->one_key)) {
+ if (State & MODE_CMDLINE) {
update_screen();
}
if (msg_grid.chars) {
diff --git a/src/nvim/message.c b/src/nvim/message.c
@@ -3069,7 +3069,7 @@ void repeat_message(void)
if (State == MODE_ASKMORE) {
msg_moremsg(true); // display --more-- message again
msg_row = Rows - 1;
- } else if (State == MODE_CMDLINE && confirm_msg != NULL) {
+ } else if ((State & MODE_CMDLINE) && confirm_msg != NULL) {
display_confirm_msg(); // display ":confirm" message again
msg_row = Rows - 1;
} else if (State == MODE_EXTERNCMD) {
diff --git a/src/nvim/state.c b/src/nvim/state.c
@@ -185,11 +185,11 @@ void get_mode(char *buf)
int i = 0;
if (State == MODE_HITRETURN || State == MODE_ASKMORE || State == MODE_SETWSIZE
- || (State == MODE_CMDLINE && get_cmdline_info()->one_key)) {
+ || ((State & MODE_CMDLINE) && get_cmdline_info()->one_key)) {
buf[i++] = 'r';
if (State == MODE_ASKMORE) {
buf[i++] = 'm';
- } else if (State == MODE_CMDLINE) {
+ } else if (State & MODE_CMDLINE) {
buf[i++] = '?';
}
} else if (State == MODE_EXTERNCMD) {
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
@@ -544,7 +544,7 @@ void ui_flush(void)
cmdline_ui_flush();
- if (State != MODE_CMDLINE && curwin->w_floating && curwin->w_config.hide) {
+ if (!(State & MODE_CMDLINE) && curwin->w_floating && curwin->w_config.hide) {
if (!was_busy) {
ui_call_busy_start();
was_busy = true;
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua
@@ -860,6 +860,16 @@ describe('cmdline redraw', function()
]])
command('redraw')
screen:expect_unchanged()
+
+ command('set keymap=dvorak')
+ feed('<C-^>')
+ command('redraw')
+ screen:expect_unchanged()
+
+ feed('<C-^>')
+ command('set keymap&')
+ command('redraw')
+ screen:expect_unchanged()
end)
it('substitute confirm prompt does not scroll', function()
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
@@ -10470,6 +10470,15 @@ describe('float window', function()
]],
})
end
+
+ command('set keymap=dvorak')
+ feed('<C-^>')
+ screen:expect_unchanged()
+
+ feed('<C-^>')
+ command('set keymap&')
+ screen:expect_unchanged()
+
feed('<ESC>')
-- Show cursor after switching to a normal window (hide=false).
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
@@ -6445,10 +6445,10 @@ describe('builtin popupmenu', function()
menu PopUp.baz :let g:menustr = 'baz'<CR>
]])
- --- @param state string|test.function.ui.screen.Expect
+ --- @param state string|test.functional.ui.screen.Expect
--- @param str string
--- @param repl string
- --- @return string|test.function.ui.screen.Expect
+ --- @return string|test.functional.ui.screen.Expect
local function screen_replace(state, str, repl)
if type(state) == 'string' then
local new_state = state:gsub(vim.pesc(str), vim.pesc(repl))
@@ -6461,7 +6461,7 @@ describe('builtin popupmenu', function()
return new_state
end
- local no_sel_screen ---@type string|test.function.ui.screen.Expect
+ local no_sel_screen ---@type string|test.functional.ui.screen.Expect
if multigrid then
api.nvim_input_mouse('right', 'press', '', 2, 0, 4)
no_sel_screen = {
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
@@ -368,7 +368,7 @@ for _, v in ipairs(ext_keys) do
expect_keys[v] = true
end
---- @class test.function.ui.screen.Expect
+--- @class test.functional.ui.screen.Expect
---
--- Expected screen state (string). Each line represents a screen
--- row. Last character of each row (typically "|") is stripped.
@@ -463,7 +463,7 @@ end
--- or keyword args (supports more options):
--- screen:expect({ grid=[[...]], cmdline={...}, condition=function() ... end })
---
---- @param expected string|function|test.function.ui.screen.Expect
+--- @param expected string|function|test.functional.ui.screen.Expect
--- @param attr_ids? table<integer,table<string,any>>
function Screen:expect(expected, attr_ids, ...)
--- @type string, fun()