aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-04-20 20:22:54 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2019-06-25 18:08:21 +0200
commitb0c1e2ab5a46a9ab040d8b2be37196d4d00d3944 (patch)
tree15df396056ee75f26548603328ddced5b56c5095 /src/nvim/api/vim.c
parent4c4d964eeb8d49a305306761eea406e1829b31ac (diff)
downloadrneovim-b0c1e2ab5a46a9ab040d8b2be37196d4d00d3944.tar.gz
rneovim-b0c1e2ab5a46a9ab040d8b2be37196d4d00d3944.tar.bz2
rneovim-b0c1e2ab5a46a9ab040d8b2be37196d4d00d3944.zip
api: make nvim__inspect_cell support multiple grids
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c30
1 files 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()) {