refactor(buffer): move the current window cursor lookup to utils

This commit is contained in:
dualfroz committed 2026-10-03 18:54:01 +02:00
1 parent 990e567f55
commit 111b528272
3 files changed
+21 -18

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
import { NeovimClient } from "neovim";
import { Position } from "vscode";
/**
* Get the (0, 0)-indexed byte cursor of the current neovim window, if it shows the given buffer
*/
export async function getCurrentWinCursorInBuf(client: NeovimClient, bufId: number): Promise<Position | undefined> {
const cursor = (await client.lua(
`
local buf = ...
if vim.api.nvim_get_current_buf() == buf then
return vim.api.nvim_win_get_cursor(0)
end
`,
[bufId],
)) as [number, number] | null;
return cursor ? new Position(cursor[0] - 1, cursor[1]) : undefined;
}