fix(pum): check for cmdline mode properly

Backport of #35198 and #35210
This commit is contained in:
zeertzjq
2025-08-07 07:56:58 +08:00
parent 54c2ea142a
commit 7f1e112a32
2 changed files with 22 additions and 14 deletions

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

View File

@@ -4130,7 +4130,7 @@ describe('builtin popupmenu', function()
]]) ]])
end end
-- not rightleft on the cmdline -- oldtest: Test_wildmenu_pum_rightleft()
feed('<esc>:sign ') feed('<esc>:sign ')
if multigrid then if multigrid then
screen:expect({ screen:expect({
@@ -4154,9 +4154,8 @@ describe('builtin popupmenu', function()
]], ]],
} }
end end
-- Not rightleft on the cmdline.
-- oldtest: Test_wildmenu_pum_rightleft() feed('<Tab>')
feed('<tab>')
if multigrid then if multigrid then
screen:expect({ screen:expect({
grid = [[ grid = [[
@@ -4195,6 +4194,15 @@ describe('builtin popupmenu', function()
]], ]],
} }
end 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) end)
it('with rightleft vsplits', function() it('with rightleft vsplits', function()