Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Win.linemap, which translates visual line numbers to file line numbers #1181

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/vis-std.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,10 @@ static const struct luaL_Reg registers_funcs[] = {

/***
* Viewport currently being displayed.
* @tfield Range viewport
* Changing these values will not move the viewport.
* @table viewport
* @tfield Range bytes
* @tfield Range lines
*/
/***
* The window width.
Expand Down Expand Up @@ -1867,8 +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);
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;
}

Expand Down
Loading