ui_pum_get_pos: return internal pum position if external pum pos not found

This commit is contained in:
Yatao Li
2020-03-03 17:43:02 +08:00
parent 630ec6cfb8
commit 9c85caa390
4 changed files with 40 additions and 41 deletions

View File

@@ -2352,10 +2352,10 @@ nvim_ui_pum_set_bounds({width}, {height}, {row}, {col})
including visual decorations such as boarders and sliders. including visual decorations such as boarders and sliders.
Parameters: ~ Parameters: ~
{width} Popupmenu width, must be greater than zero. {width} Popupmenu width.
{height} Popupmenu height, must be greater than zero. {height} Popupmenu height.
{row} Popupmenu row, must be greater or equal to zero. {row} Popupmenu row.
{height} Popupmenu height, must be greater or equal to zero. {height} Popupmenu height.
nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()* nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()*
TODO: Documentation TODO: Documentation

View File

@@ -357,11 +357,11 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
/// including visual decorations such as boarders and sliders. /// including visual decorations such as boarders and sliders.
/// ///
/// @param channel_id /// @param channel_id
/// @param width Popupmenu width, must be greater than zero. /// @param width Popupmenu width.
/// @param height Popupmenu height, must be greater than zero. /// @param height Popupmenu height.
/// @param row Popupmenu row, must be greater or equal to zero. /// @param row Popupmenu row.
/// @param col Popupmenu height, must be greater or equal to zero. /// @param col Popupmenu height.
/// @param[out] err Error details, if any. On error, suspend pum position reporting for the current UI. /// @param[out] err Error details, if any.
void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height, void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height,
Integer row, Integer col, Error *err) Integer row, Integer col, Error *err)
FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY
@@ -375,31 +375,21 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height,
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
if (!ui->ui_ext[kUIPopupmenu]) { if (!ui->ui_ext[kUIPopupmenu]) {
api_set_error(err, kErrorTypeValidation, api_set_error(err, kErrorTypeValidation,
"It must support the ext_popupmenu option"); "UI must support the ext_popupmenu option");
return; return;
} }
if (row < 0) { if (row < 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0");
ui->pum_pos = false;
return; return;
} } else if (col < 0) {
if (col < 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0"); api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0");
ui->pum_pos = false;
return; return;
} } else if (width <= 0) {
if (width <= 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0"); api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0");
ui->pum_pos = false;
return; return;
} } else if (height <= 0) {
if (height <= 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0");
ui->pum_pos = false;
return; return;
} }

View File

@@ -902,6 +902,18 @@ int pum_get_height(void)
return pum_height; 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". /// Add size information about the pum to "dict".
void pum_set_event_info(dict_T *dict) void pum_set_event_info(dict_T *dict)
{ {
@@ -909,17 +921,11 @@ void pum_set_event_info(dict_T *dict)
return; return;
} }
int w,h,r,c; int w,h,r,c;
if (!ui_pum_get_pos(&w, &h, &r, &c)){ ui_pum_get_pos(&w, &h, &r, &c);
tv_dict_add_nr(dict, S_LEN("height"), pum_height);
tv_dict_add_nr(dict, S_LEN("width"), pum_width);
tv_dict_add_nr(dict, S_LEN("row"), pum_row);
tv_dict_add_nr(dict, S_LEN("col"), pum_col);
} else {
tv_dict_add_nr(dict, S_LEN("height"), h); tv_dict_add_nr(dict, S_LEN("height"), h);
tv_dict_add_nr(dict, S_LEN("width"), w); tv_dict_add_nr(dict, S_LEN("width"), w);
tv_dict_add_nr(dict, S_LEN("row"), r); tv_dict_add_nr(dict, S_LEN("row"), r);
tv_dict_add_nr(dict, S_LEN("col"), c); tv_dict_add_nr(dict, S_LEN("col"), c);
}
tv_dict_add_nr(dict, S_LEN("size"), pum_size); tv_dict_add_nr(dict, S_LEN("size"), pum_size);
tv_dict_add_special(dict, S_LEN("scrollbar"), tv_dict_add_special(dict, S_LEN("scrollbar"),
pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse); pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse);

View File

@@ -226,7 +226,7 @@ int ui_pum_get_height(void)
{ {
int pum_height = 0; int pum_height = 0;
for (size_t i = 1; i < ui_count; i++) { for (size_t i = 1; i < ui_count; i++) {
int ui_pum_height = uis[i]->pum_height; int ui_pum_height = uis[i]->pum_nlines;
if (ui_pum_height) { if (ui_pum_height) {
pum_height = pum_height =
pum_height != 0 ? MIN(pum_height, ui_pum_height) : ui_pum_height; pum_height != 0 ? MIN(pum_height, ui_pum_height) : ui_pum_height;
@@ -235,7 +235,7 @@ int ui_pum_get_height(void)
return pum_height; return pum_height;
} }
bool ui_pum_get_pos(int* pwidth, int *pheight, int* prow, int* pcol) void ui_pum_get_pos(int* pwidth, int *pheight, int* prow, int* pcol)
{ {
int w=0,h=0,r=-1,c=-1; int w=0,h=0,r=-1,c=-1;
bool found = false; bool found = false;
@@ -254,11 +254,14 @@ bool ui_pum_get_pos(int* pwidth, int *pheight, int* prow, int* pcol)
c = MIN(uis[i]->pum_col, c); c = MIN(uis[i]->pum_col, c);
} }
} }
if (found) {
*pwidth = w; *pwidth = w;
*pheight = h; *pheight = h;
*prow = r; *prow = r;
*pcol = c; *pcol = c;
return found; } else {
pum_get_internal_pos(pwidth, pheight, prow, pcol);
}
} }
static void ui_refresh_event(void **argv) static void ui_refresh_event(void **argv)