You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/window.md
+12-6Lines changed: 12 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ Border content is generated by `quickui#utils#make_border()` as text lines, writ
58
58
|`mode`| Number | 0 | Lifecycle state (0=not created/closed, 1=created) |
59
59
|`opts`| Dict | {} | Deep copy of creation options |
60
60
|`info`| Dict | {} | Internal environment data computed during initialization |
61
-
|`quit`| Number | 0 | Whether closed by close button (Vim only, set via callback) |
61
+
|`quit`| Number | 0 | Whether closed by close button (Vim: set via popup callback; Neovim: set by `mouse_click()` when click lands on border window's close button) |
62
62
63
63
### `info` Dictionary Internal Fields
64
64
@@ -117,11 +117,13 @@ Creates and displays a window. If the window is already open, it first calls `cl
117
117
Closes the window and releases all resources.
118
118
119
119
**Behavior**:
120
-
- Vim: Calls `popup_close()`
121
-
- Neovim: Calls `nvim_win_close()` for both content and border windows
120
+
- Vim: Calls `popup_close()` (wrapped in `try/catch` for safety)
121
+
- Neovim: Calls `nvim_win_close()` for both content and border windows (each wrapped in `try/catch`)
122
122
- Releases content buffer and border buffer (`quickui#core#buffer_free()`)
123
123
- Resets `winid=-1`, `bid=-1`, `mode=0`, `hide=0`
124
124
125
+
All window-close calls are protected by `try/catch`, so calling `close()` on an already-closed window or a window closed externally (by user action or autocmd) is safe and will not throw errors. Resource cleanup (buffer release, state reset) is always performed regardless of whether the close call succeeds.
126
+
125
127
#### `win.show(show)`
126
128
127
129
Controls window visibility.
@@ -215,7 +217,7 @@ Executes Ex commands in the window context.
215
217
- If the window is open (`winid >= 0`), executes immediately via `quickui#core#win_execute()`
216
218
- If the window is not yet shown, commands are appended to `info.pending_cmd` and automatically executed when the window is displayed
217
219
218
-
This deferred execution mechanism ensures that commands set before window creation are not lost.
220
+
Commands cached via `execute()` before `open()` are preserved across the `open()` call — they will be consumed (executed and cleared) when the window is first shown. Multiple `execute()` calls accumulate commands in order.
219
221
220
222
### Syntax Highlighting Methods
221
223
@@ -258,10 +260,12 @@ call win.syntax_end()
258
260
259
261
Handles a mouse click event, returning the click position relative to the window content area.
260
262
261
-
**Returns**: Dict `{'x': col, 'y': row}`, coordinates are 0-based. Returns `{'x': -1, 'y': -1}` if the click is not within this window.
263
+
**Returns**: Dict `{'x': col, 'y': row}`, coordinates are 0-based. Returns `{'x': -1, 'y': -1}` if the click is not within the content window.
262
264
263
265
Automatically subtracts the border offset when borders are present.
264
266
267
+
**Neovim close button detection**: On Neovim, if the click lands on the border window's close button position (top-right corner) and `opts.button` is enabled, `self.quit` is set to `1`. This unifies the close button behavior across both platforms — consumers can check `win.quit` without writing platform-specific code.
268
+
265
269
### Other Methods
266
270
267
271
#### `win.refresh()`
@@ -365,5 +369,7 @@ call win.syntax_end()
365
369
2.**Coordinate system**: `x`/`y` use 0-based coordinates, but Vim's popup API uses 1-based coordinates — window.vim handles the +1 conversion internally.
366
370
3.**Border dimensions**: `tw`/`th` is the total size including border + padding, `w`/`h` is the pure content area size. `move()`'s boundary clamping is based on `tw`/`th`.
367
371
4.**Buffer management**: window uses `quickui#core#buffer_alloc/free` for buffer pool management. Do not manipulate buffers directly, and do not use `bid` after `close()`.
368
-
5.**quit property**: Only effective on Vim — set to 1 via the `popup_exit` callback when the user clicks the close button. Neovim has no such mechanism.
372
+
5.**quit property**: On Vim, set to 1 via the `popup_exit` callback when the user clicks the close button. On Neovim, set to 1 by `mouse_click()` when the click lands on the border window's close button (requires `opts.button` enabled). Consumers can check `win.quit` uniformly on both platforms.
369
373
6.**mode property**: `0` means the window is not created or has been closed, `1` means created. Most methods return early when `mode==0`.
374
+
7.**close() is safe to call multiple times**: All window-close operations are wrapped in `try/catch`. Calling `close()` on an already-closed window, or a window destroyed externally, will not throw — resource cleanup always runs.
375
+
8.**Deferred execute() across open()**: Commands cached via `execute()` before `open()` survive the `open()` call and are consumed when the window is first shown.
0 commit comments