fix(core): preserve async asset insertion anchors#152
Open
xiaoxiaowen610 wants to merge 1 commit into
Open
Conversation
问题:资源上传完成时按当前选区逐个插入,上传期间移动光标或编辑原选区会导致落点漂移、覆盖新内容,并产生多个撤销步骤。 实现:使用 CodeMirror StateField 追踪并映射发起时的所有选区和拖放锚点;串行上传后将成功项以单事务原子插入,并处理并发批次、部分失败、只读、setDocument 和 destroy 生命周期。 复现:粘贴或拖入资源后,在上传 Promise 结束前移动光标、修改原选区或发起第二批上传;旧实现会在完成时插入到错误位置或拆成多次文档修改。
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 / 摘要
Preserve paste and drop insertion anchors while asset uploads are pending, then insert each successful batch in one document transaction.
在资源异步上传期间保持粘贴和拖放的原始插入位置,并将同批成功结果通过一次文档事务原子插入。
Motivation / 背景与动机
The default asset fallback previously called
replaceSelection()after every upload resolved. That used the selection at completion time rather than the position where the paste or drop started: moving the cursor redirected the Markdown, editing the original selection could overwrite newer content, and multi-file uploads created multiple undo steps.Changes / 变更内容
packages/core:StateFieldand map it through document transactions.setDocument()or editor destruction, and skip the default pipeline in read-only editors.apps/electron-demo/openspec: N/ATesting / 测试
pnpm typecheckpnpm test— 34 files, 551 testspnpm buildpnpm build:electron-demosetDocument(), composition, read-only mode, and destruction.onAssetUpload, and this change adds no visible UI.Compliance / 合规自检
.envfiles, or personal vault data committed.Checklist / 自检清单
live-preview-table.ts: N/A.Screenshots / Recordings
N/A — no visible UI changes.