fix(plugin-toolbar): make formatting commands atomic for undo/redo#129
Open
sky86888 wants to merge 1 commit into
Open
fix(plugin-toolbar): make formatting commands atomic for undo/redo#129sky86888 wants to merge 1 commit into
sky86888 wants to merge 1 commit into
Conversation
|
|
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 / 摘要
我是李伟,在boss上得到这份作业,提交至此。
Make all toolbar formatting commands atomic so each action creates a single undo/redo entry.
让所有工具栏格式化命令支持原子操作,每个操作只需一次撤销/重做即可完全恢复。
Motivation / 背景与动机
Several formatting commands in
plugin-toolbarusededitor.setDocument()followed byeditor.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 事务。导致用户执行一个格式化操作后,需要按两次撤销才能完全恢复(第一次撤销选区,第二次才恢复文档内容)。Changes / 变更内容
packages/plugin-toolbar:toggleWrap()to usereplaceRange()instead ofsetDocument()+setSelection()insertLink()to usereplaceRange()toggleHeading()to usereplaceRange()toggleLinePrefix()/toggleBlockquote()to usereplaceRange()insertCodeBlock()to usereplaceRange()insertImage()to usereplaceRange()applyTextColor()to usereplaceRange()applyHighlight()to usereplaceRange()insertHorizontalRule()to usereplaceRange()toggleBold,insertLink, andtoggleHeadingTesting / 测试
pnpm testpasses / 全绿 — 48 tests in plugin-toolbar all passpnpm build) / 受影响包构建通过toggleBold — atomic undo(2 tests)insertLink — atomic undo(1 test)toggleHeading — atomic undo(1 test)Compliance / 合规自检
AI-assisted notes / AI 使用说明:
AI assisted with code refactoring pattern identification and test case writing.
.env/ personal vault data committedChecklist / 自检清单
live-preview-table.ts→ walked through the 12 Table Widget rules — 不涉及Screenshots / Recordings · 截图或录屏 (UI changes)
N/A — No UI changes, only internal transaction behavior fix.