fix: use direct panel selection for document editor to prevent toggle-close#4828
Conversation
…-close Address review feedback on PR #4512 (#4639 follow-up): - Replace windowState.togglePanel(.documentEditor) with windowState.selection = .panel(.documentEditor) in handleDocumentEditorShow and handleDocumentLoadResponse to avoid accidentally closing the editor panel when a second document_editor_show or document_load_response message arrives while the panel is already open (e.g. when multiple document preview widgets are present in chat and the user clicks one whose document is already loaded) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 467c3706ae
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ) | ||
| show() | ||
| windowState.togglePanel(.documentEditor) | ||
| windowState.selection = .panel(.documentEditor) |
There was a problem hiding this comment.
Persist document editor as active panel when opening it
Setting windowState.selection directly here (and similarly in handleDocumentLoadResponse) drops the persistence side effect that togglePanel used to provide via lastActivePanelString in MainWindowState.togglePanel. As a result, after opening a document editor from these daemon messages, restoreLastActivePanel() can no longer restore the document editor on reconnect/app restart and may reopen a stale previous panel instead, which is a regression from the prior behavior.
Useful? React with 👍 / 👎.
Summary
Addresses review feedback on PR #4512 (document preview widget in chat).
The P1 review comment noted that tapping a document preview widget when
the editor panel is already open with a different document could accidentally
close the panel (since
togglePanelacts as a toggle). This fix replacestogglePanel(.documentEditor)withwindowState.selection = .panel(.documentEditor)in both
handleDocumentEditorShowandhandleDocumentLoadResponseso that openingthe document editor is always an open operation, never a close.
Changes
clients/macos/vellum-assistant/Features/MainWindow/MainWindow.swift: ReplacewindowState.togglePanel(.documentEditor)withwindowState.selection = .panel(.documentEditor)in
handleDocumentEditorShowandhandleDocumentLoadResponseto prevent accidentallyclosing the panel when a second show message arrives while the panel is already open
(e.g. when multiple document preview widgets are present in chat).
Context
The P2 fix (persisting document preview surfaces across app restarts) was addressed
in PR #4639 by auto-tracking
ui_surface_showmessages from tools incurrentTurnSurfacesso they are serialised into the assistant message atmessage_completeand survive thread reloads.Test plan
document_create🤖 Generated with Claude Code