Skip to content

fix(core): preserve async asset insertion anchors#152

Open
xiaoxiaowen610 wants to merge 1 commit into
floatboatai:mainfrom
xiaoxiaowen610:fix/core-async-asset-insertion
Open

fix(core): preserve async asset insertion anchors#152
xiaoxiaowen610 wants to merge 1 commit into
floatboatai:mainfrom
xiaoxiaowen610:fix/core-async-asset-insertion

Conversation

@xiaoxiaowen610

Copy link
Copy Markdown

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.

  • Issue: none
  • Roadmap: N/A — bug fix
  • OpenSpec change: N/A — internal bug fix with no public API or new capability

Changes / 变更内容

  • packages/core:
    • Track every initiating selection range in a CodeMirror StateField and map it through document transactions.
    • Preserve selection-boundary and multi-cursor semantics; derive drop anchors from pointer coordinates.
    • Upload files serially, isolate individual failures, and commit successful results in one undoable transaction.
    • Discard stale results after setDocument() or editor destruction, and skip the default pipeline in read-only editors.
  • Other packages / apps/electron-demo / openspec: N/A

Testing / 测试

  • pnpm typecheck
  • pnpm test — 34 files, 551 tests
  • pnpm build
  • pnpm build:electron-demo
  • New Vitest coverage for mapped anchors, touched selections and boundaries, multi-cursor paste, pointer-based drop, atomic batches and undo, partial/all failures, out-of-order batches, setDocument(), composition, read-only mode, and destruction.
  • Manual UI check in electron-demo: N/A — the demo does not configure onAssetUpload, and this change adds no visible UI.

Compliance / 合规自检

  • CLA signed — I will complete the first-contributor bot prompt after this PR opens.
  • AI disclosure: the functional code in this PR is not primarily generated by AI.
    • AI tools assisted with design discussion, edge-case review, and regression-test suggestions. The functional implementation was authored and reviewed by the contributor.
  • New dependencies: none.
  • No build artifacts committed.
  • No secrets, .env files, or personal vault data committed.

Checklist / 自检清单

  • Title follows Conventional Commits.
  • Public API changes update package README / types: N/A — no public API changes.
  • Touched live-preview-table.ts: N/A.
  • New capability / breaking change requires OpenSpec: N/A.
  • Change aligns with the project scope.

Screenshots / Recordings

N/A — no visible UI changes.

问题:资源上传完成时按当前选区逐个插入,上传期间移动光标或编辑原选区会导致落点漂移、覆盖新内容,并产生多个撤销步骤。

实现:使用 CodeMirror StateField 追踪并映射发起时的所有选区和拖放锚点;串行上传后将成功项以单事务原子插入,并处理并发批次、部分失败、只读、setDocument 和 destroy 生命周期。

复现:粘贴或拖入资源后,在上传 Promise 结束前移动光标、修改原选区或发起第二批上传;旧实现会在完成时插入到错误位置或拆成多次文档修改。
@CLAassistant

CLAassistant commented Jul 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants