fix: keep prompt caret stable during autosave (#57)#58
Merged
hehehai merged 1 commit intohehehai:mainfrom May 6, 2026
Merged
Conversation
The prompt TextEditor was bound directly to a featureSettings field whose parent reassigns the entire FeatureSettings struct on every debounced save (saveFeatureSettings -> reloadFeatureSettings). SwiftUI then re-stringifies the underlying NSTextView, which collapses the caret to the end of the document mid-typing. Decouple the editor from the persisted binding: FeaturePromptSection now owns a local draft @State, the TextEditor is bound to the draft, and we push the draft into the parent binding (and call persistChanges) only at flush time. External mutations to the bound text are still pulled into the draft, but round-trip echoes of our own writes are ignored, so the NSTextView never gets a redundant string assignment while the user is typing.
Owner
|
补充说明一下这次在 PR 上追加的修改:
本地验证结果:
这几处改动的目标是把这次提示词 autosave 修复补成一组可维护、可回归验证的改动,同时恢复本地测试体验。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The prompt TextEditor was bound directly to a featureSettings field whose parent reassigns the entire FeatureSettings struct on every debounced save (saveFeatureSettings -> reloadFeatureSettings). SwiftUI then re-stringifies the underlying NSTextView, which collapses the caret to the end of the document mid-typing.
Decouple the editor from the persisted binding: FeaturePromptSection now owns a local draft @State, the TextEditor is bound to the draft, and we push the draft into the parent binding (and call persistChanges) only at flush time. External mutations to the bound text are still pulled into the draft, but round-trip echoes of our own writes are ignored, so the NSTextView never gets a redundant string assignment while the user is typing.