api: make nvim__inspect_cell support multiple grids
This commit is contained in:
parent
4c4d964eeb
commit
b0c1e2ab5a
|
@ -30,6 +30,7 @@
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
|
#include "nvim/popupmnu.h"
|
||||||
#include "nvim/edit.h"
|
#include "nvim/edit.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/eval/typval.h"
|
#include "nvim/eval/typval.h"
|
||||||
|
@ -2239,16 +2240,33 @@ void nvim_select_popupmenu_item(Integer item, Boolean insert, Boolean finish,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NB: if your UI doesn't use hlstate, this will not return hlstate first time
|
/// NB: if your UI doesn't use hlstate, this will not return hlstate first time
|
||||||
Array nvim__inspect_cell(Integer row, Integer col, Error *err)
|
Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err)
|
||||||
{
|
{
|
||||||
Array ret = ARRAY_DICT_INIT;
|
Array ret = ARRAY_DICT_INIT;
|
||||||
if (row < 0 || row >= default_grid.Rows
|
|
||||||
|| col < 0 || col >= default_grid.Columns) {
|
// TODO(bfredl): if grid == 0 we should read from the compositor's buffer.
|
||||||
|
// The only problem is that it does not yet exist.
|
||||||
|
ScreenGrid *g = &default_grid;
|
||||||
|
if (grid == pum_grid.handle) {
|
||||||
|
g = &pum_grid;
|
||||||
|
} else if (grid > 1) {
|
||||||
|
win_T *wp = get_win_by_grid_handle((handle_T)grid);
|
||||||
|
if (wp != NULL && wp->w_grid.chars != NULL) {
|
||||||
|
g = &wp->w_grid;
|
||||||
|
} else {
|
||||||
|
api_set_error(err, kErrorTypeValidation,
|
||||||
|
"No grid with the given handle");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row < 0 || row >= g->Rows
|
||||||
|
|| col < 0 || col >= g->Columns) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
size_t off = default_grid.line_offset[(size_t)row] + (size_t)col;
|
size_t off = g->line_offset[(size_t)row] + (size_t)col;
|
||||||
ADD(ret, STRING_OBJ(cstr_to_string((char *)default_grid.chars[off])));
|
ADD(ret, STRING_OBJ(cstr_to_string((char *)g->chars[off])));
|
||||||
int attr = default_grid.attrs[off];
|
int attr = g->attrs[off];
|
||||||
ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err)));
|
ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err)));
|
||||||
// will not work first time
|
// will not work first time
|
||||||
if (!highlight_use_hlstate()) {
|
if (!highlight_use_hlstate()) {
|
||||||
|
|
Loading…
Reference in New Issue