aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/popupmenu.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-15 22:37:48 +0800
committerGitHub <noreply@github.com>2024-06-15 22:37:48 +0800
commit203540926df0ac6faae02e35ad12ae0221e210f6 (patch)
tree79db7eeb0ac114024d92cbfdd8420c02e61877f8 /src/nvim/popupmenu.c
parentc5e3321aa14d323cb91a69de42ec0d66bef58a30 (diff)
downloadrneovim-203540926df0ac6faae02e35ad12ae0221e210f6.tar.gz
rneovim-203540926df0ac6faae02e35ad12ae0221e210f6.tar.bz2
rneovim-203540926df0ac6faae02e35ad12ae0221e210f6.zip
vim-patch:9.1.0491: Cmdline pum doesn't work properly with 'rightleft' (#29355)
Problem: Cmdline pum doesn't work properly with 'rightleft'. Solution: Don't use curwin->w_p_rl in cmdline mode in pum_redraw(). Use a static variable since pum_may_redraw() may be called in any mode. Also correct position of other popups with 'rightleft'. (zeertzjq) closes: vim/vim#15005 https://github.com/vim/vim/commit/883018feff43413813770dd1e13d4f950aa38524
Diffstat (limited to 'src/nvim/popupmenu.c')
-rw-r--r--src/nvim/popupmenu.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c
index b8e7630802..6f8f858247 100644
--- a/src/nvim/popupmenu.c
+++ b/src/nvim/popupmenu.c
@@ -143,7 +143,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
|| (State == MODE_CMDLINE && ui_has(kUIWildmenu));
}
- pum_rl = (curwin->w_p_rl && State != MODE_CMDLINE);
+ pum_rl = State != MODE_CMDLINE && curwin->w_p_rl;
do {
// Mark the pum as visible already here,
@@ -450,7 +450,7 @@ static void pum_puts_with_attr(int col, char *text, hlf_T hlf)
}
char *rt_leader = NULL;
- if (curwin->w_p_rl) {
+ if (pum_rl) {
rt_leader = reverse_text(leader);
}
char *match_leader = rt_leader != NULL ? rt_leader : leader;
@@ -1212,12 +1212,14 @@ void pum_set_event_info(dict_T *dict)
static void pum_position_at_mouse(int min_width)
{
int min_row = 0;
+ int min_col = 0;
int max_row = Rows;
int max_col = Columns;
if (mouse_grid > 1) {
win_T *wp = get_win_by_grid_handle(mouse_grid);
if (wp != NULL) {
min_row = -wp->w_winrow;
+ min_col = -wp->w_wincol;
max_row = MAX(Rows - wp->w_winrow, wp->w_grid.rows);
max_col = MAX(Columns - wp->w_wincol, wp->w_grid.cols);
}
@@ -1230,6 +1232,7 @@ static void pum_position_at_mouse(int min_width)
} else {
pum_anchor_grid = mouse_grid;
}
+
if (max_row - mouse_row > pum_size) {
// Enough space below the mouse row.
pum_above = false;
@@ -1246,16 +1249,29 @@ static void pum_position_at_mouse(int min_width)
pum_row = min_row;
}
}
- if (max_col - mouse_col >= pum_base_width
- || max_col - mouse_col > min_width) {
- // Enough space to show at mouse column.
- pum_col = mouse_col;
+
+ if (pum_rl) {
+ if (mouse_col - min_col + 1 >= pum_base_width
+ || mouse_col - min_col + 1 > min_width) {
+ // Enough space to show at mouse column.
+ pum_col = mouse_col;
+ } else {
+ // Not enough space, left align with window.
+ pum_col = min_col + MIN(pum_base_width, min_width) - 1;
+ }
+ pum_width = pum_col - min_col + 1;
} else {
- // Not enough space, right align with window.
- pum_col = max_col - (pum_base_width > min_width ? min_width : pum_base_width);
+ if (max_col - mouse_col >= pum_base_width
+ || max_col - 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 = max_col - MIN(pum_base_width, min_width);
+ }
+ pum_width = max_col - pum_col;
}
- pum_width = max_col - pum_col;
if (pum_width > pum_base_width + 1) {
pum_width = pum_base_width + 1;
}
@@ -1337,6 +1353,7 @@ void pum_show_popupmenu(vimmenu_T *menu)
pum_compute_size();
pum_scrollbar = 0;
pum_height = pum_size;
+ pum_rl = curwin->w_p_rl;
pum_position_at_mouse(20);
pum_selected = -1;
@@ -1416,7 +1433,9 @@ void pum_make_popup(const char *path_name, int use_mouse_pos)
// Hack: set mouse position at the cursor so that the menu pops up
// around there.
mouse_row = curwin->w_grid.row_offset + curwin->w_wrow;
- mouse_col = curwin->w_grid.col_offset + curwin->w_wcol;
+ mouse_col = curwin->w_grid.col_offset
+ + (curwin->w_p_rl ? curwin->w_width_inner - curwin->w_wcol - 1
+ : curwin->w_wcol);
if (ui_has(kUIMultigrid)) {
mouse_grid = curwin->w_grid.target->handle;
} else if (curwin->w_grid.target != &default_grid) {