diff --git a/lua/vis-std.lua b/lua/vis-std.lua index 5dd13eb28..1fe93a9d9 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -54,7 +54,7 @@ vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win) if not lexer then return end -- TODO: improve heuristic for initial style - local viewport = win.viewport + local viewport = win.viewport.bytes if not viewport then return end local horizon_max = win.horizon or 32768 local horizon = viewport.start < horizon_max and viewport.start or horizon_max diff --git a/vis-lua.c b/vis-lua.c index 96f2fb803..2c4e0b7e2 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -531,24 +531,6 @@ static void pushrange(lua_State *L, Filerange *r) { lua_settable(L, -3); } -static void pushlinemap(lua_State *L, Win *win) { - if (!win || !win->view) { - lua_pushnil(L); - return; - } - View *view = win->view; - Line *line = view_lines_first(view); - size_t lines = view_height_get(view); - lua_createtable(L, lines, 0); - for (lua_Integer l = 1; l <= lines; l++) { - if (!line) - break; - lua_pushunsigned(L, line->lineno); - lua_seti(L, -2, l); - line = line->next; - } -} - static Filerange getrange(lua_State *L, int index) { Filerange range = text_range_empty(); if (lua_istable(L, index)) { @@ -1849,11 +1831,10 @@ static const struct luaL_Reg registers_funcs[] = { /*** * Viewport currently being displayed. - * @tfield Range viewport - */ -/*** - * A list mapping lines in the viewport to logical lines in the file. - * @tfield list linemap + * Changing these values will not move the viewport. + * @table viewport + * @tfield Range bytes + * @tfield Range lines */ /*** * The window width. @@ -1889,13 +1870,18 @@ static int window_index(lua_State *L) { const char *key = lua_tostring(L, 2); if (strcmp(key, "viewport") == 0) { - Filerange r = view_viewport_get(win->view); - pushrange(L, &r); - return 1; - } - - if (strcmp(key, "linemap") == 0) { - pushlinemap(L, win); + Filerange b = view_viewport_get(win->view); + Filerange l; + l.start = view_lines_first(win->view)->lineno; + l.end = view_lines_last(win->view)->lineno; + + lua_createtable(L, 0, 2); + lua_pushstring(L, "bytes"); + pushrange(L, &b); + lua_settable(L, -3); + lua_pushstring(L, "lines"); + pushrange(L, &l); + lua_settable(L, -3); return 1; }