mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 01:46:29 +00:00
api/ui: simplify popup menu position get/set logic; fix test
This commit is contained in:
@@ -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.
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user