File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,49 @@ export async function open(
175175 } ;
176176}
177177
178+ /**
179+ * Close a popup window by its window ID.
180+ *
181+ * This function closes a popup window in both Vim and Neovim using the
182+ * appropriate platform-specific method. After closing, it automatically
183+ * triggers a redraw to ensure the UI is updated.
184+ *
185+ * @param denops - The Denops instance
186+ * @param winid - The window ID of the popup window to close
187+ *
188+ * @example
189+ * ```typescript
190+ * import type { Entrypoint } from "jsr:@denops/std";
191+ * import * as popup from "jsr:@denops/std/popup";
192+ *
193+ * export const main: Entrypoint = async (denops) => {
194+ * // Open a popup window
195+ * const popupWindow = await popup.open(denops, {
196+ * relative: "editor",
197+ * width: 20,
198+ * height: 20,
199+ * row: 1,
200+ * col: 1,
201+ * });
202+ *
203+ * // Do something with the popup window...
204+ *
205+ * // Close the popup window using the standalone close function
206+ * await popup.close(denops, popupWindow.winid);
207+ * }
208+ * ```
209+ *
210+ * Note that this function does NOT work in `batch.collect()`.
211+ */
212+ export async function close (
213+ denops : Denops ,
214+ winid : number ,
215+ ) : Promise < void > {
216+ const close = denops . meta . host === "vim" ? closePopupVim : closePopupNvim ;
217+ await close ( denops , winid ) ;
218+ await denops . redraw ( ) ;
219+ }
220+
178221/**
179222 * Config a popup window in Vim/Neovim compatible way.
180223 *
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments