Skip to content

Commit ba9ef4b

Browse files
committed
feat(popup): support relative: cursor in vim
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
1 parent 88f227a commit ba9ef4b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

popup/vim.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,26 @@ function toPopupCreateOptions(
3737
};
3838
}
3939

40+
function handleRelative(
41+
relative: "editor" | "cursor",
42+
offset?: number,
43+
): string | number | undefined {
44+
if (offset == undefined) {
45+
return undefined;
46+
}
47+
if (relative == "editor") {
48+
return offset;
49+
} else {
50+
return offset < 0 ? `cursor${offset}` : `cursor+${offset}`;
51+
}
52+
}
53+
4054
function toPopupSetOptionsOptions(
4155
options: Partial<Omit<OpenOptions, "bufnr" | "noRedraw">>,
4256
): vimFn.PopupSetOptionsOptions {
4357
const v: vimFn.PopupCreateOptions = {
44-
line: options.row,
45-
col: options.col,
58+
line: handleRelative(options.relative ?? "editor", options.row),
59+
col: handleRelative(options.relative ?? "editor", options.col),
4660
pos: options.anchor ? posFromAnchor(options.anchor) : undefined,
4761
fixed: true, // To keep consistent with the behavior of Neovim's floating window
4862
flip: false, // To keep consistent with the behavior of Neovim's floating window

0 commit comments

Comments
 (0)