Merge pull request #35224 from zeertzjq/backport

Backport #35198 #35202 #35210
This commit is contained in:
zeertzjq
2025-08-08 06:31:10 +08:00
committed by GitHub
9 changed files with 50 additions and 23 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

@@ -139,10 +139,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// To keep the code simple, we only allow changing the
// draw mode when the popup menu is not being displayed
pum_external = ui_has(kUIPopupmenu)
|| (State == MODE_CMDLINE && ui_has(kUIWildmenu));
|| ((State & MODE_CMDLINE) && ui_has(kUIWildmenu));
}
pum_rl = State != MODE_CMDLINE && curwin->w_p_rl;
pum_rl = (State & MODE_CMDLINE) == 0 && curwin->w_p_rl;
do {
// Mark the pum as visible already here,
@@ -154,7 +154,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
int below_row = cmdline_row;
// wildoptions=pum
if (State == MODE_CMDLINE) {
if (State & MODE_CMDLINE) {
pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row;
cursor_col = cmd_startcol;
pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE;
@@ -244,7 +244,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// pum above "pum_win_row"
pum_above = true;
if (State == MODE_CMDLINE) {
if (State & MODE_CMDLINE) {
// for cmdline pum, no need for context lines
context_lines = 0;
} else {
@@ -268,7 +268,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// pum below "pum_win_row"
pum_above = false;
if (State == MODE_CMDLINE) {
if (State & MODE_CMDLINE) {
// for cmdline pum, no need for context lines
context_lines = 0;
} else {
@@ -404,7 +404,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// room the window size will keep changing.
} while (pum_set_selected(selected, redo_count) && ++redo_count <= 2);
pum_grid.zindex = (State == MODE_CMDLINE) ? kZIndexCmdlinePopupMenu : kZIndexPopupMenu;
pum_grid.zindex = (State & MODE_CMDLINE) ? kZIndexCmdlinePopupMenu : kZIndexPopupMenu;
pum_redraw();
}
@@ -418,15 +418,15 @@ static int *pum_compute_text_attrs(char *text, hlf_T hlf, int user_hlattr)
return NULL;
}
char *leader = State == MODE_CMDLINE ? cmdline_compl_pattern()
: ins_compl_leader();
char *leader = (State & MODE_CMDLINE) ? cmdline_compl_pattern()
: ins_compl_leader();
if (leader == NULL || *leader == NUL) {
return NULL;
}
int *attrs = xmalloc(sizeof(int) * (size_t)vim_strsize(text));
bool in_fuzzy = State == MODE_CMDLINE ? cmdline_compl_is_fuzzy()
: (get_cot_flags() & kOptCotFlagFuzzy) != 0;
bool in_fuzzy = (State & MODE_CMDLINE) ? cmdline_compl_is_fuzzy()
: (get_cot_flags() & kOptCotFlagFuzzy) != 0;
size_t leader_len = strlen(leader);
garray_T *ga = NULL;

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

@@ -4130,7 +4130,7 @@ describe('builtin popupmenu', function()
]])
end
-- not rightleft on the cmdline
-- oldtest: Test_wildmenu_pum_rightleft()
feed('<esc>:sign ')
if multigrid then
screen:expect({
@@ -4154,9 +4154,8 @@ describe('builtin popupmenu', function()
]],
}
end
-- oldtest: Test_wildmenu_pum_rightleft()
feed('<tab>')
-- Not rightleft on the cmdline.
feed('<Tab>')
if multigrid then
screen:expect({
grid = [[
@@ -4195,6 +4194,15 @@ describe('builtin popupmenu', function()
]],
}
end
-- Behavior is the same when using 'keymap'.
feed('<Esc>')
command('set keymap=dvorak')
-- ";gul" -> "sign" when using Dvorak keymap.
feed(':<C-^>;gul <Tab>')
screen:expect_unchanged(true)
feed('<Esc>')
command('set keymap&')
end)
it('with rightleft vsplits', function()

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()