From d24fb72c335be905d0b7f2c67f9b988f07703d1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Oct 2024 14:29:59 +0800 Subject: fix(pum): don't select item when clicking to the left/right (#30967) Problem: Selecting an item in the right-click menu when clicking to the left/right of it is confusing, especially in a UI that doesn't support 'mousemoveevent'. Solution: Don't select an item when clicking to the left/right of the right-click menu. --- src/nvim/popupmenu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 87ef6a27ad..529d65c5dc 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1358,14 +1358,15 @@ static void pum_select_mouse_pos(void) if (mouse_grid == pum_grid.handle) { pum_selected = mouse_row; return; - } else if (mouse_grid != pum_anchor_grid) { + } else if (mouse_grid != pum_anchor_grid || mouse_col < pum_grid.comp_col + || mouse_col >= pum_grid.comp_col + pum_grid.comp_width) { pum_selected = -1; return; } - int idx = mouse_row - pum_row; + int idx = mouse_row - pum_grid.comp_row; - if (idx < 0 || idx >= pum_height) { + if (idx < 0 || idx >= pum_grid.comp_height) { pum_selected = -1; } else if (*pum_array[idx].pum_text != NUL) { pum_selected = idx; -- cgit