mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
external pum: use floating point geometry; typval: add tv_dict_add_float
This commit is contained in:
parent
9c85caa390
commit
6da16ac931
@ -111,10 +111,10 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
|
||||
ui->height = (int)height;
|
||||
ui->pum_nlines = 0;
|
||||
ui->pum_pos = false;
|
||||
ui->pum_width = 0;
|
||||
ui->pum_height = 0;
|
||||
ui->pum_row = -1;
|
||||
ui->pum_col = -1;
|
||||
ui->pum_width = 0.0;
|
||||
ui->pum_height = 0.0;
|
||||
ui->pum_row = -1.0;
|
||||
ui->pum_col = -1.0;
|
||||
ui->rgb = true;
|
||||
ui->override = false;
|
||||
ui->grid_resize = remote_ui_grid_resize;
|
||||
@ -349,12 +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
|
||||
/// 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,
|
||||
/// 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.
|
||||
@ -362,9 +365,9 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
|
||||
/// @param row Popupmenu row.
|
||||
/// @param col Popupmenu height.
|
||||
/// @param[out] err Error details, if any.
|
||||
void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height,
|
||||
Integer row, Integer col, Error *err)
|
||||
FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY
|
||||
void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height,
|
||||
Float row, Float col, Error *err)
|
||||
FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY
|
||||
{
|
||||
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
|
||||
api_set_error(err, kErrorTypeException,
|
||||
@ -393,10 +396,10 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Integer width, Integer height,
|
||||
return;
|
||||
}
|
||||
|
||||
ui->pum_row = (int)row;
|
||||
ui->pum_col = (int)col;
|
||||
ui->pum_width = (int)width;
|
||||
ui->pum_height = (int)height;
|
||||
ui->pum_row = (double)row;
|
||||
ui->pum_col = (double)col;
|
||||
ui->pum_width = (double)width;
|
||||
ui->pum_height = (double)height;
|
||||
ui->pum_pos = true;
|
||||
}
|
||||
|
||||
|
@ -1634,6 +1634,28 @@ int tv_dict_add_nr(dict_T *const d, const char *const key,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Add a floating point number entry to dictionary
|
||||
///
|
||||
/// @param[out] d Dictionary to add entry to.
|
||||
/// @param[in] key Key to add.
|
||||
/// @param[in] key_len Key length.
|
||||
/// @param[in] nr Floating point number to add.
|
||||
///
|
||||
/// @return OK in case of success, FAIL when key already exists.
|
||||
int tv_dict_add_float(dict_T *const d, const char *const key,
|
||||
const size_t key_len, const float_T nr)
|
||||
{
|
||||
dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
|
||||
|
||||
item->di_tv.v_type = VAR_FLOAT;
|
||||
item->di_tv.vval.v_float = nr;
|
||||
if (tv_dict_add(d, item) == FAIL) {
|
||||
tv_dict_item_free(item);
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Add a special entry to dictionary
|
||||
///
|
||||
/// @param[out] d Dictionary to add entry to.
|
||||
|
@ -906,7 +906,7 @@ int pum_get_height(void)
|
||||
///
|
||||
/// @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)
|
||||
void pum_get_internal_pos(int *pwidth, int *pheight, int *prow, int *pcol)
|
||||
{
|
||||
*pwidth = pum_width;
|
||||
*pheight = pum_height;
|
||||
@ -920,12 +920,12 @@ void pum_set_event_info(dict_T *dict)
|
||||
if (!pum_visible()) {
|
||||
return;
|
||||
}
|
||||
int w,h,r,c;
|
||||
double w, h, r, c;
|
||||
ui_pum_get_pos(&w, &h, &r, &c);
|
||||
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("row"), r);
|
||||
tv_dict_add_nr(dict, S_LEN("col"), c);
|
||||
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);
|
||||
tv_dict_add_float(dict, S_LEN("col"), c);
|
||||
tv_dict_add_nr(dict, S_LEN("size"), pum_size);
|
||||
tv_dict_add_special(dict, S_LEN("scrollbar"),
|
||||
pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse);
|
||||
|
@ -979,9 +979,9 @@ func Test_CompleteChanged()
|
||||
call cursor(4, 1)
|
||||
|
||||
call feedkeys("Sf\<C-N>", 'tx')
|
||||
call assert_equal({'completed_item': {}, 'width': 15,
|
||||
\ 'height': 2, 'size': 2,
|
||||
\ 'col': 0, 'row': 4, 'scrollbar': v:false}, g:event)
|
||||
call assert_equal({'completed_item': {}, 'width': 15.0,
|
||||
\ 'height': 2.0, 'size': 2,
|
||||
\ 'col': 0.0, 'row': 4.0, 'scrollbar': v:false}, g:event)
|
||||
call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx')
|
||||
call assert_equal('foo', g:word)
|
||||
call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
|
||||
@ -1009,10 +1009,10 @@ func Test_pum_getpos()
|
||||
setlocal completefunc=UserDefinedComplete
|
||||
|
||||
let d = {
|
||||
\ 'height': 5,
|
||||
\ 'width': 15,
|
||||
\ 'row': 1,
|
||||
\ 'col': 0,
|
||||
\ 'height': 5.0,
|
||||
\ 'width': 15.0,
|
||||
\ 'row': 1.0,
|
||||
\ 'col': 0.0,
|
||||
\ 'size': 5,
|
||||
\ 'scrollbar': v:false,
|
||||
\ }
|
||||
|
@ -235,12 +235,14 @@ int ui_pum_get_height(void)
|
||||
return pum_height;
|
||||
}
|
||||
|
||||
void ui_pum_get_pos(int* pwidth, int *pheight, int* prow, int* pcol)
|
||||
void ui_pum_get_pos(double *pwidth, double *pheight, double *prow, double *pcol)
|
||||
{
|
||||
int w=0,h=0,r=-1,c=-1;
|
||||
double w = 0.0, h = 0.0, r = -1.0, c = -1.0;
|
||||
bool found = false;
|
||||
for (size_t i = 1; i < ui_count; i++) {
|
||||
if (!uis[i]->pum_pos) continue;
|
||||
if (!uis[i]->pum_pos) {
|
||||
continue;
|
||||
}
|
||||
if (!found) {
|
||||
w = uis[i]->pum_width;
|
||||
h = uis[i]->pum_height;
|
||||
@ -260,7 +262,12 @@ void ui_pum_get_pos(int* pwidth, int *pheight, int* prow, int* pcol)
|
||||
*prow = r;
|
||||
*pcol = c;
|
||||
} else {
|
||||
pum_get_internal_pos(pwidth, pheight, prow, pcol);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,12 @@ struct ui_t {
|
||||
bool ui_ext[kUIExtCount]; ///< Externalized UI capabilities.
|
||||
int width;
|
||||
int height;
|
||||
int pum_nlines; /// actual nr. lines shown in PUM
|
||||
bool pum_pos; /// UI reports back pum position?
|
||||
int pum_row;
|
||||
int pum_col;
|
||||
int pum_height;
|
||||
int pum_width;
|
||||
int pum_nlines; /// actual nr. lines shown in PUM
|
||||
bool pum_pos; /// UI reports back pum position?
|
||||
double pum_row;
|
||||
double pum_col;
|
||||
double pum_height;
|
||||
double pum_width;
|
||||
void *data;
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
Loading…
Reference in New Issue
Block a user