From 7833fb8bc0e3f9ece01ab2fe6fe07ded0efc4af4 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 27 May 2026 20:48:12 -0500 Subject: fix(vterm): never reopen the F9/F12 windows from the top F9 brought the agent window down from the top of the frame. The toggle remembers where the window last sat and replays it, and "above" was a position it could capture and replay: move the window to the top with the buffer-move keys, toggle off, and the next toggle reopened it up there. The host default never picks the top, so a remembered "above" was the only way in. I added an optional allowed-directions list to cj/window-toggle-capture-state, the helper both F9 (ai-vterm) and F12 (vterm-config) share. When the captured direction isn't in the list, it falls back to the default direction and clears the saved size, since that size was measured on the disallowed axis and wouldn't transfer. Both dispatchers now pass (right below left), so neither can remember a top placement. They go through the same helper, so the rule stays in one place. Three tests cover the new branch: a permitted direction is kept, a disallowed one falls back with the size cleared, and an omitted list preserves the old unconstrained behavior so existing callers are unaffected. --- modules/cj-window-toggle-lib.el | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'modules/cj-window-toggle-lib.el') diff --git a/modules/cj-window-toggle-lib.el b/modules/cj-window-toggle-lib.el index ef57e5cf..9874a134 100644 --- a/modules/cj-window-toggle-lib.el +++ b/modules/cj-window-toggle-lib.el @@ -20,7 +20,8 @@ (require 'cj-window-geometry-lib) (defun cj/window-toggle-capture-state (window default-direction - direction-var size-var) + direction-var size-var + &optional allowed) "Write WINDOW's direction and body size into DIRECTION-VAR and SIZE-VAR. DEFAULT-DIRECTION is the symbol used by `cj/window-direction' when @@ -28,12 +29,24 @@ WINDOW fills its frame's root area. DIRECTION-VAR and SIZE-VAR are the symbols of the consumer's state variables; they receive the captured values via `set'. +ALLOWED, when non-nil, is a list of permitted direction symbols. If +WINDOW's captured direction isn't in it, fall back to DEFAULT-DIRECTION +and clear SIZE-VAR (set to nil) so the consumer's default size applies -- +the captured body size was measured on the disallowed axis and wouldn't +transfer meaningfully. A consumer that wants to forbid a placement (e.g. +an agent window that should never be remembered at the top of the frame) +passes the directions it does allow. Omit ALLOWED to keep every +direction. + No-op when WINDOW is nil or not live." (when (window-live-p window) - (let* ((dir (cj/window-direction window default-direction)) - (size (cj/window-body-size window dir))) - (set direction-var dir) - (set size-var size)))) + (let ((dir (cj/window-direction window default-direction))) + (if (or (null allowed) (memq dir allowed)) + (progn + (set direction-var dir) + (set size-var (cj/window-body-size window dir))) + (set direction-var default-direction) + (set size-var nil))))) (defun cj/window-toggle-display-saved (buffer alist direction-var default-direction -- cgit v1.2.3