From b0c1e2ab5a46a9ab040d8b2be37196d4d00d3944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Sat, 20 Apr 2019 20:22:54 +0200 Subject: [PATCH] api: make nvim__inspect_cell support multiple grids --- src/nvim/api/vim.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2e8ca384b4..72eb68b650 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -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()) {