aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYatao Li <yatli@microsoft.com>2020-03-22 17:53:45 +0800
committerYatao Li <yatli@microsoft.com>2020-04-28 01:54:16 +0800
commite34684b2ad02e759dec39c0f0958c7882120ecdc (patch)
treecc2024053865052d34e7e8ebebbd45a4064d29ee /src
parentd372c804aa33a272f6659f6d08d5dfee704d30d9 (diff)
downloadrneovim-e34684b2ad02e759dec39c0f0958c7882120ecdc.tar.gz
rneovim-e34684b2ad02e759dec39c0f0958c7882120ecdc.tar.bz2
rneovim-e34684b2ad02e759dec39c0f0958c7882120ecdc.zip
api/ui: simplify popup menu position get/set logic; fix test
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/ui.c18
-rw-r--r--src/nvim/popupmnu.c19
-rw-r--r--src/nvim/ui.c29
3 files changed, 22 insertions, 44 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 300f409a0f..717713b948 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -349,15 +349,15 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
ui->pum_nlines = (int)height;
}
-/// Tells Nvim the geometry of the popumenu, to align floating
-/// windows with an external popup menu. Note that this method
-/// is not to be confused with |nvim_ui_pum_set_height()|, which
-/// sets the number of visible items in the popup menu, while
-/// this function sets the bounding box of the popup menu,
-/// including visual decorations such as boarders and sliders.
-/// Floats need not use the same font size, nor be anchored to
-/// exact grid corners, so one can set floating-point numbers
-/// to the popup menu geometry.
+/// Tells Nvim the geometry of the popumenu, to align floating windows with an
+/// external popup menu.
+///
+/// Note that this method is not to be confused with |nvim_ui_pum_set_height()|,
+/// which sets the number of visible items in the popup menu, while this
+/// function sets the bounding box of the popup menu, including visual
+/// decorations such as boarders and sliders. Floats need not use the same font
+/// size, nor be anchored to exact grid corners, so one can set floating-point
+/// numbers to the popup menu geometry.
///
/// @param channel_id
/// @param width Popupmenu width.
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index 051cd660db..532bf68190 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -902,18 +902,6 @@ int pum_get_height(void)
return pum_height;
}
-/// Gets the internal pum geometry.
-///
-/// @return the internal pum geometry. Ignores UI external pum geometry.
-/// Only valid when pum_visible() returns TRUE!
-void pum_get_internal_pos(int *pwidth, int *pheight, int *prow, int *pcol)
-{
- *pwidth = pum_width;
- *pheight = pum_height;
- *prow = pum_row;
- *pcol = pum_col;
-}
-
/// Add size information about the pum to "dict".
void pum_set_event_info(dict_T *dict)
{
@@ -921,7 +909,12 @@ void pum_set_event_info(dict_T *dict)
return;
}
double w, h, r, c;
- ui_pum_get_pos(&w, &h, &r, &c);
+ if (!ui_pum_get_pos(&w, &h, &r, &c)) {
+ w = (double)pum_width;
+ h = (double)pum_height;
+ r = (double)pum_row;
+ c = (double)pum_col;
+ }
tv_dict_add_float(dict, S_LEN("height"), h);
tv_dict_add_float(dict, S_LEN("width"), w);
tv_dict_add_float(dict, S_LEN("row"), r);
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 0a8474ff82..685da77b39 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -235,34 +235,19 @@ int ui_pum_get_height(void)
return pum_height;
}
-void ui_pum_get_pos(double *pwidth, double *pheight, double *prow, double *pcol)
+bool ui_pum_get_pos(double *pwidth, double *pheight, double *prow, double *pcol)
{
- double w = 0.0, h = 0.0, r = 0.0, c = 0.0;
- bool found = false;
for (size_t i = 1; i < ui_count; i++) {
if (!uis[i]->pum_pos) {
continue;
}
- w = uis[i]->pum_width;
- h = uis[i]->pum_height;
- r = uis[i]->pum_row;
- c = uis[i]->pum_col;
- found = true;
- break;
- }
- if (found) {
- *pwidth = w;
- *pheight = h;
- *prow = r;
- *pcol = c;
- } else {
- int iw, ih, ir, ic;
- pum_get_internal_pos(&iw, &ih, &ir, &ic);
- *pwidth = (double)iw;
- *pheight = (double)ih;
- *prow = (double)ir;
- *pcol = (double)ic;
+ *pwidth = uis[i]->pum_width;
+ *pheight = uis[i]->pum_height;
+ *prow = uis[i]->pum_row;
+ *pcol = uis[i]->pum_col;
+ return true;
}
+ return false;
}
static void ui_refresh_event(void **argv)