fix(ui): check for cmdline mode properly

Backport of #35202
This commit is contained in:
zeertzjq
2025-08-07 12:22:01 +08:00
parent 7f1e112a32
commit 6fd842a4fd
7 changed files with 28 additions and 9 deletions

View File

@@ -272,7 +272,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".
@@ -374,8 +374,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) {

View File

@@ -3062,7 +3062,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) {

View File

@@ -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) {

View File

@@ -541,7 +541,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;

View File

@@ -1141,6 +1141,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()

View File

@@ -9587,6 +9587,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).

View File

@@ -365,7 +365,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.
@@ -460,7 +460,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()