api: make nvim__inspect_cell support multiple grids

This commit is contained in:
Björn Linse 2019-04-20 20:22:54 +02:00
parent 4c4d964eeb
commit b0c1e2ab5a
1 changed files with 24 additions and 6 deletions

View File

@ -30,6 +30,7 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/popupmnu.h"
#include "nvim/edit.h"
#include "nvim/eval.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
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;
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;
}
size_t off = default_grid.line_offset[(size_t)row] + (size_t)col;
ADD(ret, STRING_OBJ(cstr_to_string((char *)default_grid.chars[off])));
int attr = default_grid.attrs[off];
size_t off = g->line_offset[(size_t)row] + (size_t)col;
ADD(ret, STRING_OBJ(cstr_to_string((char *)g->chars[off])));
int attr = g->attrs[off];
ADD(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, err)));
// will not work first time
if (!highlight_use_hlstate()) {