Skip to content

fix(plugin-toolbar): make formatting commands atomic for undo/redo#129

Open
sky86888 wants to merge 1 commit into
floatboatai:mainfrom
sky86888:fix/toolbar-atomic-undo
Open

fix(plugin-toolbar): make formatting commands atomic for undo/redo#129
sky86888 wants to merge 1 commit into
floatboatai:mainfrom
sky86888:fix/toolbar-atomic-undo

Conversation

@sky86888

@sky86888 sky86888 commented Jul 4, 2026

Copy link
Copy Markdown

Summary / 摘要

我是李伟,在boss上得到这份作业,提交至此。

Make all toolbar formatting commands atomic so each action creates a single undo/redo entry.

让所有工具栏格式化命令支持原子操作,每个操作只需一次撤销/重做即可完全恢复。

Motivation / 背景与动机

Several formatting commands in plugin-toolbar used editor.setDocument() followed by editor.setSelection(), which creates two separate CodeMirror transactions. This means users need to press undo twice to fully revert a single formatting action — once to restore the selection and once to restore the document content.

plugin-toolbar 中的多个格式化命令使用了 editor.setDocument() + editor.setSelection() 的组合,这会创建两个独立的 CodeMirror 事务。导致用户执行一个格式化操作后,需要按两次撤销才能完全恢复(第一次撤销选区,第二次才恢复文档内容)。

  • Issue: N/A
  • Roadmap (docs/ROADMAP.md): P1 — Power-user features / undo/redo grouping
  • OpenSpec change: N/A (internal refactor, no API change)

Changes / 变更内容

  • packages/plugin-toolbar:
    • Refactored toggleWrap() to use replaceRange() instead of setDocument() + setSelection()
    • Refactored insertLink() to use replaceRange()
    • Refactored toggleHeading() to use replaceRange()
    • Refactored toggleLinePrefix() / toggleBlockquote() to use replaceRange()
    • Refactored insertCodeBlock() to use replaceRange()
    • Refactored insertImage() to use replaceRange()
    • Refactored applyTextColor() to use replaceRange()
    • Refactored applyHighlight() to use replaceRange()
    • Refactored insertHorizontalRule() to use replaceRange()
    • Added atomic undo test cases for toggleBold, insertLink, and toggleHeading

Testing / 测试

  • pnpm test passes / 全绿 — 48 tests in plugin-toolbar all pass
  • Affected packages build (pnpm build) / 受影响包构建通过
  • New / updated vitest cases / 新增或更新的 vitest 用例:
    • toggleBold — atomic undo (2 tests)
    • insertLink — atomic undo (1 test)
    • toggleHeading — atomic undo (1 test)
  • Manual UI check in electron-demo / electron-demo 手动验证:
    • Bold toggle: select text → Ctrl+B → Ctrl+Z → single undo fully restores
    • Heading toggle: cursor on line → Ctrl+2 → Ctrl+Z → single undo fully restores
    • Insert link: select text → Ctrl+K → Ctrl+Z → single undo fully restores

Compliance / 合规自检

  • CLA signed — first-time contributors will be prompted automatically by the CLA bot
  • AI disclosure: the functional code in this PR is not primarily generated by AI. AI assistance, if any, is described below.
    AI-assisted notes / AI 使用说明:
    AI assisted with code refactoring pattern identification and test case writing.
  • New dependencies (if any) listed with license & rationale:
  • No build artifacts committed
  • No secrets / .env / personal vault data committed

Checklist / 自检清单

  • Title follows Conventional Commits / 标题遵循 Conventional Commits
  • Public API changes update package README / types — 无 API 变更
  • Touched live-preview-table.ts → walked through the 12 Table Widget rules — 不涉及
  • New capability / breaking change → OpenSpec proposal linked — 不涉及,纯内部重构
  • Change aligns with project scope (GOVERNANCE.md §4)

Screenshots / Recordings · 截图或录屏 (UI changes)

image

N/A — No UI changes, only internal transaction behavior fix.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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