fix(pum): position properly with ext_multigrid (#23336)

This commit is contained in:
zeertzjq 2023-04-27 20:19:21 +08:00 committed by GitHub
parent 4b3fdf321c
commit a3dfe1bc89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3396 additions and 2612 deletions

View File

@ -133,6 +133,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
validate_cursor_col();
int above_row = 0;
int below_row = cmdline_row;
int row_off = 0;
int col_off = 0;
// wildoptions=pum
if (State == MODE_CMDLINE) {
@ -151,7 +153,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
pum_anchor_grid = (int)curwin->w_grid.target->handle;
pum_win_row += curwin->w_grid.row_offset;
cursor_col += curwin->w_grid.col_offset;
if (!ui_has(kUIMultigrid) && curwin->w_grid.target != &default_grid) {
if (ui_has(kUIMultigrid)) {
row_off = curwin->w_winrow;
col_off = curwin->w_wincol;
} else if (curwin->w_grid.target != &default_grid) {
pum_anchor_grid = (int)default_grid.handle;
pum_win_row += curwin->w_winrow;
cursor_col += curwin->w_wincol;
@ -204,14 +209,14 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
pum_height = PUM_DEF_HEIGHT;
}
if ((p_ph > 0) && (pum_height > p_ph)) {
if (p_ph > 0 && pum_height > p_ph) {
pum_height = (int)p_ph;
}
// Put the pum below "pum_win_row" if possible.
// If there are few lines decide on where there is more room.
if (pum_win_row + 2 >= below_row - pum_height
&& pum_win_row - above_row > (below_row - above_row) / 2) {
if (pum_win_row + row_off + 2 >= below_row - pum_height
&& pum_win_row + row_off - above_row > (below_row - above_row) / 2) {
// pum above "pum_win_row"
pum_above = true;
@ -227,15 +232,15 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
}
}
if (pum_win_row >= size + context_lines) {
if (pum_win_row + row_off >= size + context_lines) {
pum_row = pum_win_row - size - context_lines;
pum_height = size;
} else {
pum_row = 0;
pum_height = pum_win_row - context_lines;
pum_row = -row_off;
pum_height = pum_win_row + row_off - context_lines;
}
if ((p_ph > 0) && (pum_height > p_ph)) {
if (p_ph > 0 && pum_height > p_ph) {
pum_row += pum_height - (int)p_ph;
pum_height = (int)p_ph;
}
@ -257,26 +262,26 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
}
pum_row = pum_win_row + context_lines;
if (size > below_row - pum_row) {
pum_height = below_row - pum_row;
if (size > below_row - row_off - pum_row) {
pum_height = below_row - row_off - pum_row;
} else {
pum_height = size;
}
if ((p_ph > 0) && (pum_height > p_ph)) {
if (p_ph > 0 && pum_height > p_ph) {
pum_height = (int)p_ph;
}
}
// don't display when we only have room for one line
if ((pum_height < 1) || ((pum_height == 1) && (size > 1))) {
if (pum_height < 1 || (pum_height == 1 && size > 1)) {
return;
}
// If there is a preview window above avoid drawing over it.
if (pvwin != NULL && pum_row < above_row && pum_height > above_row) {
pum_row = above_row;
pum_height = pum_win_row - above_row;
if (pvwin != NULL && pum_row + row_off < above_row && pum_height > above_row) {
pum_row = above_row - row_off;
pum_height = pum_win_row + row_off - above_row;
}
pum_array = array;
@ -302,22 +307,23 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
def_width = max_width;
}
if ((((cursor_col < Columns - p_pw) || (cursor_col < Columns - max_width))
&& !pum_rl)
|| (pum_rl && ((cursor_col > p_pw) || (cursor_col > max_width)))) {
if (((cursor_col + col_off < Columns - p_pw
|| cursor_col + col_off < Columns - max_width) && !pum_rl)
|| (pum_rl && (cursor_col + col_off > p_pw
|| cursor_col + col_off > max_width))) {
// align pum with "cursor_col"
pum_col = cursor_col;
// start with the maximum space available
if (pum_rl) {
pum_width = pum_col - pum_scrollbar + 1;
pum_width = pum_col + col_off - pum_scrollbar + 1;
} else {
assert(Columns - pum_col - pum_scrollbar >= 0);
pum_width = Columns - pum_col - pum_scrollbar;
assert(Columns - col_off - pum_col - pum_scrollbar >= 0);
pum_width = Columns - col_off - pum_col - pum_scrollbar;
}
if ((pum_width > max_width + pum_kind_width + pum_extra_width + 1)
&& (pum_width > p_pw)) {
if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
&& pum_width > p_pw) {
// the width is more than needed for the items, make it
// narrower
pum_width = max_width + pum_kind_width + pum_extra_width + 1;
@ -325,41 +331,42 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
if (pum_width < p_pw) {
pum_width = (int)p_pw;
}
} else if (((cursor_col > p_pw || cursor_col > max_width) && !pum_rl)
|| (pum_rl && (cursor_col < Columns - p_pw
|| cursor_col < Columns - max_width))) {
} else if (((cursor_col + col_off > p_pw
|| cursor_col + col_off > max_width) && !pum_rl)
|| (pum_rl && (cursor_col + col_off < Columns - p_pw
|| cursor_col + col_off < Columns - max_width))) {
// align pum edge with "cursor_col"
if (pum_rl && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) {
pum_col = cursor_col + max_width + pum_scrollbar + 1;
if (pum_col >= Columns) {
pum_col = Columns - 1;
if (pum_col + col_off >= Columns) {
pum_col = Columns - col_off - 1;
}
} else if (!pum_rl) {
if (curwin->w_wincol > Columns - max_width - pum_scrollbar
&& max_width <= p_pw) {
// use full width to end of the screen
pum_col = Columns - max_width - pum_scrollbar;
if (pum_col < 0) {
pum_col = 0;
pum_col = Columns - col_off - max_width - pum_scrollbar;
if (pum_col + col_off < 0) {
pum_col = -col_off;
}
}
}
if (pum_rl) {
pum_width = pum_col - pum_scrollbar + 1;
pum_width = pum_col + col_off - pum_scrollbar + 1;
} else {
pum_width = Columns - pum_col - pum_scrollbar;
pum_width = Columns - col_off - pum_col - pum_scrollbar;
}
if (pum_width < p_pw) {
pum_width = (int)p_pw;
if (pum_rl) {
if (pum_width > pum_col) {
pum_width = pum_col;
if (pum_width > pum_col + col_off) {
pum_width = pum_col + col_off;
}
} else {
if (pum_width >= Columns - pum_col) {
pum_width = Columns - pum_col - 1;
if (pum_width >= Columns - col_off - pum_col) {
pum_width = Columns - col_off - pum_col - 1;
}
}
} else if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
@ -373,10 +380,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
} else if (Columns < def_width) {
// not enough room, will use what we have
if (pum_rl) {
assert(Columns - 1 >= INT_MIN);
pum_col = Columns - 1;
assert(Columns - col_off - 1 >= INT_MIN);
pum_col = Columns - col_off - 1;
} else {
pum_col = 0;
pum_col = -col_off;
}
pum_width = Columns - 1;
} else {
@ -386,10 +393,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
}
if (pum_rl) {
pum_col = max_width - 1;
pum_col = max_width - col_off - 1;
} else {
assert(Columns - max_width >= 0);
pum_col = Columns - max_width;
pum_col = Columns - col_off - max_width;
}
pum_width = max_width - pum_scrollbar;
}
@ -397,7 +404,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// Set selected item and redraw. If the window size changed need to redo
// the positioning. Limit this to two times, when there is not much
// 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_redraw();
@ -967,32 +974,42 @@ void pum_set_event_info(dict_T *dict)
static void pum_position_at_mouse(int min_width)
{
int row_off = 0;
int col_off = 0;
if (mouse_grid > 1) {
win_T *wp = get_win_by_grid_handle(mouse_grid);
if (wp != NULL) {
row_off = wp->w_winrow;
col_off = wp->w_wincol;
}
}
pum_anchor_grid = mouse_grid;
if (Rows - mouse_row > pum_size) {
if (Rows - row_off - mouse_row > pum_size) {
// Enough space below the mouse row.
pum_above = false;
pum_row = mouse_row + 1;
if (pum_height > Rows - pum_row) {
pum_height = Rows - pum_row;
if (pum_height > Rows - row_off - pum_row) {
pum_height = Rows - row_off - pum_row;
}
} else {
// Show above the mouse row, reduce height if it does not fit.
pum_above = true;
pum_row = mouse_row - pum_size;
if (pum_row < 0) {
pum_height += pum_row;
pum_row = 0;
if (pum_row + row_off < 0) {
pum_height += pum_row + row_off;
pum_row = -row_off;
}
}
if (Columns - mouse_col >= pum_base_width || Columns - mouse_col > min_width) {
if (Columns - col_off - mouse_col >= pum_base_width
|| Columns - col_off - mouse_col > min_width) {
// Enough space to show at mouse column.
pum_col = mouse_col;
} else {
// Not enough space, right align with window.
pum_col = Columns - (pum_base_width > min_width ? min_width : pum_base_width);
pum_col = Columns - col_off - (pum_base_width > min_width ? min_width : pum_base_width);
}
pum_width = Columns - pum_col;
pum_width = Columns - col_off - pum_col;
if (pum_width > pum_base_width + 1) {
pum_width = pum_base_width + 1;
}

View File

@ -1849,5 +1849,17 @@ describe('ui/mouse/input', function()
feed('<Down><CR>')
eq(2, funcs.winnr())
eq('', funcs.getreg('"'))
-- Test for right click in visual mode inside the selection with vertical splits
command('wincmd t')
command('rightbelow vsplit')
funcs.setreg('"', '')
meths.win_set_cursor(0, {1, 9})
feed('vee')
meths.input_mouse('right', 'press', '', 0, 0, 52)
meths.input_mouse('right', 'release', '', 0, 0, 52)
feed('<Down><CR>')
eq({1, 9}, meths.win_get_cursor(0))
eq('ran away', funcs.getreg('"'))
end)
end)

File diff suppressed because it is too large Load Diff