Skip to content

Commit c333087

Browse files
committed
Size side windows by body width and add test
1 parent 9c54616 commit c333087

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

ai-code-backends-infra.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Can be either `vterm' or `eat'."
6262
:group 'ai-code-backends-infra)
6363

6464
(defcustom ai-code-backends-infra-window-width 90
65-
"Width of the side window when opened on left or right."
65+
"Body width of the side window when opened on left or right."
6666
:type 'integer
6767
:group 'ai-code-backends-infra)
6868

@@ -521,7 +521,8 @@ MULTILINE-INPUT-SEQUENCE configures `S-<return>' and `C-<return>' when non-nil."
521521
(side . ,side)
522522
(slot . 0)
523523
,@(when (memq side '(left right))
524-
`((window-width . ,ai-code-backends-infra-window-width)))
524+
`((window-width
525+
. ,#'ai-code-backends-infra--fit-side-window-body-width)))
525526
,@(when (memq side '(top bottom))
526527
`((window-height . ,ai-code-backends-infra-window-height)))
527528
(window-parameters . ((no-delete-other-windows . t)))))))
@@ -532,6 +533,13 @@ MULTILINE-INPUT-SEQUENCE configures `S-<return>' and `C-<return>' when non-nil."
532533
(select-window window))
533534
window))
534535

536+
(defun ai-code-backends-infra--fit-side-window-body-width (window)
537+
"Resize WINDOW so its body width matches `ai-code-backends-infra-window-width'."
538+
(let ((delta (- ai-code-backends-infra-window-width
539+
(window-body-width window))))
540+
(unless (zerop delta)
541+
(window-resize window delta t))))
542+
535543
;;; Session Helpers
536544

537545
(defun ai-code-backends-infra--session-working-directory ()

test/test_ai-code-backends-infra.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,30 @@
215215
(advice-remove handler #'ai-code-backends-infra--terminal-reflow-filter))
216216
(fmakunbound handler)))))
217217

218+
(ert-deftest test-ai-code-backends-infra-display-buffer-in-side-window-uses-body-width ()
219+
"Horizontal side windows should size to the configured body width."
220+
(with-temp-buffer
221+
(let ((ai-code-backends-infra-use-side-window t)
222+
(ai-code-backends-infra-window-side 'right)
223+
(ai-code-backends-infra-window-width 100)
224+
(ai-code-backends-infra-focus-on-open nil)
225+
captured-entry
226+
resize-call)
227+
(rename-buffer " *ai-code-side-width*" t)
228+
(cl-letf (((symbol-function 'display-buffer)
229+
(lambda (_buffer &optional _action)
230+
(setq captured-entry (car display-buffer-alist))
231+
'fake-window))
232+
((symbol-function 'window-body-width)
233+
(lambda (_window) 96))
234+
((symbol-function 'window-resize)
235+
(lambda (window delta horizontal)
236+
(setq resize-call (list window delta horizontal)))))
237+
(ai-code-backends-infra--display-buffer-in-side-window (current-buffer))
238+
(should (functionp (cdr (assq 'window-width captured-entry))))
239+
(funcall (cdr (assq 'window-width captured-entry)) 'fake-window)
240+
(should (equal resize-call '(fake-window 4 t)))))))
241+
218242
(ert-deftest test-ai-code-backends-infra-sync-terminal-cursor-vterm-copy-mode ()
219243
"Show an Emacs cursor in vterm copy mode and restore terminal cursor on exit."
220244
(with-temp-buffer

0 commit comments

Comments
 (0)