diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-13 15:33:38 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-13 15:33:38 -0500 |
| commit | 9600611d5f8382ffc849d56a67ba5eb980d64e04 (patch) | |
| tree | 1bf5e900196513356213e9f1639b73bf01b20099 /modules | |
| parent | d97800f565810fda4e166a708e9b1df6f72d054c (diff) | |
| download | dotemacs-9600611d5f8382ffc849d56a67ba5eb980d64e04.tar.gz dotemacs-9600611d5f8382ffc849d56a67ba5eb980d64e04.zip | |
fix(ai-vterm): preserve single-window layout across F9 toggle
When the agent buffer is the only window in the frame, F9 buries it (correct) but the next F9 redisplayed it as a side split instead of restoring the full-frame layout -- the display-saved path always called `display-buffer-in-direction`, which insists on a split.
New `cj/--ai-vterm-last-was-bury` flag tracks which toggle-off path ran. `cj/ai-vterm` sets it to t in the bury branch (one-window-p) and nil in the delete-window branch. `cj/--ai-vterm-display-saved` checks the flag at toggle-on: if t and the frame is still single-window, it replaces the selected window's buffer in place rather than splitting. Either branch consumes the flag so it never stays stale.
5 tests in test-ai-vterm--single-window-toggle.el cover the flag's set/clear paths, the still-one-window guard, and the end-to-end roundtrip.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ai-vterm.el | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/modules/ai-vterm.el b/modules/ai-vterm.el index ac246ee8..1eae19f3 100644 --- a/modules/ai-vterm.el +++ b/modules/ai-vterm.el @@ -337,6 +337,16 @@ has been toggled off yet this session, so the default direction applies. Captured at toggle-off by `cj/--ai-vterm-capture-state' and consumed by `cj/--ai-vterm-display-saved'.") +(defvar cj/--ai-vterm-last-was-bury nil + "Non-nil when the last F9 toggle-off used `bury-buffer'. + +Set by `cj/ai-vterm' in its `toggle-off' branch: t when the agent +window was the only window in the frame (so toggle-off buried +without deleting), nil when the window was deleted. Consumed by +`cj/--ai-vterm-display-saved' to decide between restoring the +buried agent in the current window (the only one) or splitting per +the saved direction.") + (defvar cj/--ai-vterm-last-size nil "Last user-chosen body size for the AI-vterm display. @@ -398,12 +408,26 @@ project changes." (defun cj/--ai-vterm-display-saved (buffer alist) "Display-buffer action: split per saved direction and size. -Delegates to `cj/window-toggle-display-saved' against the F9 state -vars, falling back to `right' and `cj/ai-vterm-window-width'." - (cj/window-toggle-display-saved - buffer alist - 'cj/--ai-vterm-last-direction 'right - 'cj/--ai-vterm-last-size cj/ai-vterm-window-width)) +When the prior toggle-off was a bury (single-window state, flagged +via `cj/--ai-vterm-last-was-bury') and the frame is still single- +window, restore the agent into the selected window in place rather +than splitting -- preserves the user's lone-window layout across +F9 toggles. + +Otherwise delegates to `cj/window-toggle-display-saved' against the +F9 state vars, falling back to `right' and `cj/ai-vterm-window-width'." + (cond + ((and cj/--ai-vterm-last-was-bury (one-window-p)) + (setq cj/--ai-vterm-last-was-bury nil) + (let ((win (selected-window))) + (set-window-buffer win buffer) + win)) + (t + (setq cj/--ai-vterm-last-was-bury nil) + (cj/window-toggle-display-saved + buffer alist + 'cj/--ai-vterm-last-direction 'right + 'cj/--ai-vterm-last-size cj/ai-vterm-window-width)))) (defun cj/--ai-vterm-display-rule-list () "Return the `display-buffer-alist' entry list installed by this module. @@ -679,10 +703,17 @@ AI-vterm buffers without touching the project list." ;; other buffer in it, and the next toggle-on then creates a ;; fresh side window for a count of N+1. Skip the deletion ;; only when agent is the lone window in the frame (delete - ;; would leave none); bury in that case. - (if (one-window-p) - (bury-buffer (window-buffer win)) - (delete-window win)) + ;; would leave none); bury in that case. The flag tells the + ;; next toggle-on (via `cj/--ai-vterm-display-saved') to restore + ;; in place rather than splitting -- preserves the single-window + ;; layout across F9 toggles. + (cond + ((one-window-p) + (setq cj/--ai-vterm-last-was-bury t) + (bury-buffer (window-buffer win))) + (t + (setq cj/--ai-vterm-last-was-bury nil) + (delete-window win))) nil) (`(redisplay-recent . ,buf) (display-buffer buf) |
