Skip to content

fix: keep prompt caret stable during autosave (#57)#58

Merged
hehehai merged 1 commit intohehehai:mainfrom
blueberrycongee:fix/issue-57-prompt-cursor-jump
May 6, 2026
Merged

fix: keep prompt caret stable during autosave (#57)#58
hehehai merged 1 commit intohehehai:mainfrom
blueberrycongee:fix/issue-57-prompt-cursor-jump

Conversation

@blueberrycongee
Copy link
Copy Markdown
Contributor

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.

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.
@hehehai hehehai added the bug Something isn't working label May 6, 2026
@hehehai
Copy link
Copy Markdown
Owner

hehehai commented May 6, 2026

补充说明一下这次在 PR 上追加的修改:

  1. FeaturePromptSection 做了状态协调优化:把编辑中的 draft、外部同步值、以及 debounce flush 的判定集中到 FeaturePromptDraftCoordinator,避免 autosave / reload 时状态分散,方便后续维护和回归。
  2. 新增了 FeaturePromptDraftCoordinatorTests,覆盖初始化、正常 flush、stale debounce 忽略、忽略自身 round-trip echo、以及外部真实更新同步这几个关键场景,补齐这次光标保持修复的回归测试。
  3. 修复了 VoxtTests target 的签名配置漂移问题:之前 test bundle 被 ad-hoc 签名,导致在本机运行测试时因为 Team ID 不一致无法加载。现在已经对齐到和宿主 app 一致的开发签名,并补上 test bundle 的 Info.plist 生成配置。

本地验证结果:

  • xcodebuild build-for-testing -project Voxt.xcodeproj -scheme Voxt -configuration TestDebug -destination "platform=macOS" 通过
  • xcodebuild test-without-building -project Voxt.xcodeproj -scheme Voxt -configuration TestDebug -destination "platform=macOS" -derivedDataPath /Users/guanwei/x/doit/Voxt/build/DerivedDataFeaturePromptFixed -only-testing:VoxtTests/FeaturePromptDraftCoordinatorTests 通过(6/6)

这几处改动的目标是把这次提示词 autosave 修复补成一组可维护、可回归验证的改动,同时恢复本地测试体验。

@hehehai hehehai merged commit 556065d into hehehai:main May 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants