Skip to content

Commit ffac959

Browse files
committed
Fix editor viewport placement and recent file tracking
Keep editor viewports on the frame selected when placement starts and use a deterministic fallback order: below, right, left, then replace. Attempt below placement only when the source has at least 24 lines, target a 12-line viewport, accept an 8-line minimum, and accept side placement only when both the source and viewport remain at least 24 columns wide. Split side-window sessions directly into normal viewport windows so all four side positions follow the same fallback policy without creating same-side siblings. Roll back failed attempts, preserve restoration after layout transposition, and keep frame-producing display actions out of the controlled chain. Exclude external-editor staging files from recentf without changing user configuration. Cover dimension boundaries, normal and side-window geometry, fallback ordering, selected-frame isolation, no-frame behavior, layout transposition, restoration, cancel/save flows, and recentf bindings. Keep the transpose checks compatible with the minimum supported Emacs by exercising window-x only when it is available.
1 parent 7f87231 commit ffac959

4 files changed

Lines changed: 1193 additions & 164 deletions

ai-code-editor-viewport-transport.el

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
(require 'subr-x)
1717

1818
(declare-function ai-code-editor-viewport--open-request
19-
"ai-code-editor-viewport" (source-buffer payload))
19+
"ai-code-editor-viewport"
20+
(source-buffer payload &optional origin-frame))
2021
(declare-function ai-code-editor-viewport--schedule-submit
2122
"ai-code-editor-viewport" (source-buffer))
2223

@@ -43,6 +44,10 @@
4344
(defconst ai-code-editor-viewport--submit-ready-prefix "submit-ready:"
4445
"Prefix for completion payloads emitted after a helper is reaped.")
4546

47+
(defconst ai-code-editor-viewport--request-version
48+
"ai-code-editor-viewport-v1"
49+
"Version marker for editor request payloads with explicit request kinds.")
50+
4651
(defconst ai-code-editor-viewport--frame-prefix-environment-variable
4752
"AI_CODE_EDITOR_VIEWPORT_FRAME_PREFIX"
4853
"Environment variable containing the helper's terminal frame prefix.")
@@ -178,9 +183,10 @@ When TOKEN is nil, discard any pending token."
178183
(if (string-prefix-p ai-code-editor-viewport--submit-ready-prefix payload)
179184
(ai-code-editor-viewport--consume-submit-ready source-buffer payload)
180185
(ai-code-editor-viewport--discard-submit-token source-buffer)
181-
(run-at-time 0 nil
182-
#'ai-code-editor-viewport--open-request
183-
source-buffer payload)
186+
(let ((origin-frame (selected-frame)))
187+
(run-at-time 0 nil
188+
#'ai-code-editor-viewport--open-request
189+
source-buffer payload origin-frame))
184190
t)))
185191

186192
(defun ai-code-editor-viewport-filter-output (process output)
@@ -225,6 +231,9 @@ STATUS-DIRECTORY is where the helper creates its response files."
225231
temporary-file-directory))))
226232
(concat
227233
"#!/bin/sh\n"
234+
"request_kind=regular\n"
235+
"[ \"${1-}\" = \"--ai-code-staging\" ]"
236+
" && request_kind=staging && shift\n"
228237
"submit=0\n"
229238
"[ \"${1-}\" = \"--ai-code-submit\" ] && submit=1 && shift\n"
230239
"[ \"$#\" -gt 0 ] || exit 1\n"
@@ -239,6 +248,10 @@ STATUS-DIRECTORY is where the helper creates its response files."
239248
" printf '%s\\0' \"$status_file\"\n"
240249
" printf '%s\\0' \"${PWD-}\"\n"
241250
" printf '%s\\0' \"$submit\"\n"
251+
" printf '%s\\0' \""
252+
ai-code-editor-viewport--request-version
253+
"\"\n"
254+
" printf '%s\\0' \"$request_kind\"\n"
242255
" printf '%s\\0' \"$@\"\n"
243256
" } | base64 | tr -d '\\r\\n'\n"
244257
") || exit 1\n"
@@ -341,17 +354,18 @@ STATUS-DIRECTORY is where the helper creates its response files."
341354
"Return ENVIRONMENT configured to edit through a terminal viewport.
342355
FRAME-PREFIX, when non-nil, selects an adapter-specific terminal frame.
343356
General editor requests submit restored input when
344-
`ai-code-editor-viewport-auto-submit' is non-nil. Git editor requests only
345-
save."
357+
`ai-code-editor-viewport-auto-submit' is non-nil. They are marked as staging
358+
requests independently of submission. Git editor requests only save."
346359
(if (or (not ai-code-editor-viewport-enabled)
347360
(not (ai-code-editor-viewport--supported-p)))
348361
environment
349362
(let* ((helper (ai-code-editor-viewport--ensure-helper))
350363
(helper-command (shell-quote-argument helper))
351-
(submit-command (concat helper-command " --ai-code-submit"))
364+
(staging-command (concat helper-command " --ai-code-staging"))
365+
(submit-command (concat staging-command " --ai-code-submit"))
352366
(editor-command (if ai-code-editor-viewport-auto-submit
353367
submit-command
354-
helper-command))
368+
staging-command))
355369
(prefix (or frame-prefix
356370
(ai-code-editor-viewport--frame-prefix))))
357371
(append

0 commit comments

Comments
 (0)