Skip to content

Commit 9e57f4c

Browse files
committed
refactor(popup): simplify handleRelative function and improve option handling
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
1 parent 604f808 commit 9e57f4c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

popup/vim.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ function toPopupCreateOptions(
3939

4040
function handleRelative(
4141
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}`;
42+
offset: number,
43+
): string | number {
44+
switch (relative) {
45+
case "editor":
46+
return offset;
47+
case "cursor":
48+
return offset < 0 ? `cursor${offset}` : `cursor+${offset}`;
49+
default:
50+
unreachable(relative);
5151
}
5252
}
5353

5454
function toPopupSetOptionsOptions(
5555
options: Partial<Omit<OpenOptions, "bufnr" | "noRedraw">>,
5656
): vimFn.PopupSetOptionsOptions {
5757
const v: vimFn.PopupCreateOptions = {
58-
line: handleRelative(options.relative ?? "editor", options.row),
59-
col: handleRelative(options.relative ?? "editor", options.col),
58+
line: options.row ? handleRelative(options.relative ?? "editor", options.row) : undefined,
59+
col: options.col ? handleRelative(options.relative ?? "editor", options.col) : undefined,
6060
pos: options.anchor ? posFromAnchor(options.anchor) : undefined,
6161
fixed: true, // To keep consistent with the behavior of Neovim's floating window
6262
flip: false, // To keep consistent with the behavior of Neovim's floating window

0 commit comments

Comments
 (0)