Skip to content

Keep the composer's state with its chat (851-4335) - #1415

Merged
pondorasti merged 1 commit into
mainfrom
alexandru/851-4335-composer-state
Nov 18, 2026
Merged

pondorasti merged 1 commit into
mainfrom
alexandru/851-4335-composer-state

Conversation

@pondorasti

Copy link
Copy Markdown
Member

Part of 851-4335 (tab state in models), under 851-4331. Closes the composer gaps listed in #1413.

What changed

The composer card held its caret, slash-menu state, prompt-history position and "sending" guard as view state, and its undo history lived in the window's shared undo manager. On the reused chat page that state was reset by hand on each chat switch.

ComposerViewState (CodevisorUI, unit tested) now holds it per chat, looked up from the chat's controller the same way SessionAttachmentImages is:

  • "Sending" guard and question answering belong to the chat (and question) that started them. A submission or answer that finishes after a chat switch can no longer unblock another chat or a newer question.
  • Caret is remembered together with the draft it was placed in. For any other draft (first visit, or a draft replaced while away) it goes to the end.
  • Undo history is per chat and per editor, and is dropped whenever the draft is changed from outside the editor (send, prompt recall, another pane). Undo no longer replays one chat's edits into another, or into a draft that was replaced.
  • File and photo pickers stay view state, and a chat switch under the same view closes them, so picked files cannot attach to the wrong chat.
  • Per-chat signals (slashToken, editingQueuedPromptID) are compared through ChatSignal, so a chat swap is not mistaken for an edit.

Behaviour changes in the default mode

Small, and both improvements:

  • Opening a chat that has a draft puts the caret at the end of the draft (it was at the start), and the caret position is remembered when a tab is rebuilt.
  • Cmd+Z in one chat's composer no longer reaches edits made in another kept-alive chat's composer (they shared the window's undo manager), and undo after a send no longer applies stale edits.

Tophat (dev app, TRANSCRIPT_STRESS=1), reused page on and off

  • Typing in the middle of a draft keeps the caret in place; backspace and typing continue there.
  • Undo and redo are per chat and survive switching away and back (reused page); in the default mode they survive for kept-alive tabs, and a rebuilt tab starts with no history, as before.
  • Caret is remembered across chat switches, and across tab eviction in the default mode.
  • Drafts stay with their chat; a sent message appears only in its chat; undo after a send leaves the composer empty.
  • Slash menu opens; New Chat composer types, edits mid-draft and undoes.

Checks: swift test for ComposerViewStateTests, ComposerPromptHistoryTests, TranscriptPresentationMountTests; swift:format:check; swift:lint; build:ios.

🤖 Generated with Claude Code

The composer card held its caret, slash-menu state, prompt-history position
and "sending" guard as view state, and its undo history in the window's
shared undo manager. On the reused chat page that state had to be reset by
hand on every chat switch, and a submission that finished after a switch
cleared the guard of whichever chat was showing.

ComposerViewState (CodevisorUI) now holds this per chat:

- The "sending" guard and the question being answered belong to the chat
  that started them, so a late finish cannot unblock another chat or a newer
  question.
- The caret is remembered with the draft it was placed in; for any other
  draft it goes to the end.
- Undo history is kept per chat and per editor, dropped when the draft is
  changed from outside the editor, so undo never replays one chat's edits
  into another or into a draft that was replaced.
- A chat switch closes an open file or photo picker instead of attaching the
  picked files to the chat that is now showing.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant