fix(core): flush debounced change before silent mutations - #355
Open
xujing-sys wants to merge 1 commit into
Open
xujing-sys wants to merge 1 commit into
xujing-sys wants to merge 1 commit into
Conversation
When parseDelayMs is enabled, a pending onChange timer could fire after a silent setDocument or replaceRange and emit stale Markdown against the new document. Flush the scheduled change first so hosts see the last user edit once and AST stays aligned with the loaded buffer. Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
This branch has not been deployed
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.
Summary / 摘要
在 silent 的
setDocument/replaceRange执行前,先 flush 尚未触发的 debouncedonChange,避免定时器在新文档加载后仍 emit 旧 Markdown,保证宿主最后一次用户编辑只通知一次,且 AST 与当前缓冲区一致。Motivation / 背景与动机
当
parseDelayMs > 0时,用户编辑会延迟触发onChange与 AST 同步。宿主在 debounce 窗口内用setDocument(..., { silent: true })(例如打开文件、React/Vue 受控value同步)或 silentreplaceRange替换内容时,旧的 parse 定时器仍可能随后触发,向 已加载的新文档 emit 上一版 Markdown,造成getDocument()/getAst()/onChange不一致。Changes / 变更内容
packages/core:performSetDocument:当opts.silent === true时,在替换文档前调用flushScheduledChangeNow()。replaceRange:当opts.silent === true时,在 dispatch 前同样 flush。view.state.docemit 一次 change,再执行 silent 突变;silent 路径仍不触发多余的 hostonChange。packages/plugin-*: N/Aapps/electron-demo: N/Aopenspec/: N/ATesting / 测试
npx pnpm@9.15.4 exec vitest run packages/core/test/editor.test.ts -t "flushes a pending"— 2 passednpx pnpm@9.15.4 --filter @floatboat/nexus-core build— 通过pnpm test全仓(建议在 CI 或本地补跑后勾选)flushes a pending user change before a silent setDocumentflushes a pending user change before a silent replaceRangeCompliance / 合规自检
editor.ts改动与editor.test.ts回归用例;设计决策(仅 silent 路径 flush、复用现有flushScheduledChangeNow)由贡献者确认。.envcommittedChecklist / 自检清单
live-preview-table.ts— 未修改Screenshots / Recordings · 截图或录屏 (UI changes)
N/A — 无可见 UI 变更。