Skip to content

Commit bae3c6a

Browse files
committed
Add close function to popup module
1 parent 4a275c5 commit bae3c6a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

popup/mod.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ export async function open(
175175
};
176176
}
177177

178+
/**
179+
* Close popup window
180+
*/
181+
export async function close(
182+
denops: Denops,
183+
winid: number,
184+
): Promise<void> {
185+
const close = denops.meta.host === "vim" ? closePopupVim : closePopupNvim;
186+
await close(denops, winid);
187+
await denops.redraw();
188+
}
189+
178190
/**
179191
* Config a popup window in Vim/Neovim compatible way.
180192
*

popup/mod_test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,28 @@ test({
105105
},
106106
});
107107
}
108+
109+
await t.step({
110+
name: `close() closes a popup window by window ID`,
111+
fn: async () => {
112+
const popupWindow = await popup.open(denops, {
113+
relative: "editor",
114+
width: 30,
115+
height: 30,
116+
row: 10,
117+
col: 10,
118+
});
119+
const { winid } = popupWindow;
120+
121+
// Verify popup is open
122+
assertEquals(await fn.win_gettype(denops, winid), "popup");
123+
124+
// Close using standalone close() function
125+
await popup.close(denops, winid);
126+
127+
// Verify popup is closed
128+
assertEquals(await fn.win_gettype(denops, winid), "unknown");
129+
},
130+
});
108131
},
109132
});

0 commit comments

Comments
 (0)