Skip to content

refactor: migrate to Codemirror@6 and update editor functionalities#1586

Merged
RSS1102 merged 29 commits intodevfrom
upgrade_codemirror_v6_251213
Apr 3, 2026
Merged

refactor: migrate to Codemirror@6 and update editor functionalities#1586
RSS1102 merged 29 commits intodevfrom
upgrade_codemirror_v6_251213

Conversation

@RSS1102
Copy link
Copy Markdown
Collaborator

@RSS1102 RSS1102 commented Jan 2, 2026

close #1204

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 2, 2026

🦋 Changeset detected

Latest commit: 3615599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
cherry-markdown Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 2, 2026

Open in StackBlitz

pnpm add https://pkg.pr.new/cherry-markdown@1586
npm i https://pkg.pr.new/cherry-markdown@1586
yarn add https://pkg.pr.new/cherry-markdown@1586.tgz

commit: 3615599

@cherry-markdown-bot
Copy link
Copy Markdown
Collaborator

cherry-markdown-bot commented Jan 2, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 2, 2026

Size Change: +686 kB (+10.58%) ⚠️

Total Size: 7.17 MB

📦 View Changed
Filename Size Change
packages/cherry-markdown/dist/cherry-markdown.core.js 673 kB +87 kB (+14.83%) ⚠️
packages/cherry-markdown/dist/cherry-markdown.css 35.2 kB -1.9 kB (-5.12%)
packages/cherry-markdown/dist/cherry-markdown.engine.core.esm.js 301 kB +16.5 kB (+5.81%) 🔍
packages/cherry-markdown/dist/cherry-markdown.engine.core.js 301 kB +16.5 kB (+5.8%) 🔍
packages/cherry-markdown/dist/cherry-markdown.esm.js 1.59 MB +125 kB (+8.53%) 🔍
packages/cherry-markdown/dist/cherry-markdown.js 2.71 MB +263 kB (+10.73%) ⚠️
packages/cherry-markdown/dist/cherry-markdown.min.css 27.7 kB -1.05 kB (-3.65%)
packages/cherry-markdown/dist/cherry-markdown.stream.esm.js 482 kB +88.5 kB (+22.47%) 🚨
packages/cherry-markdown/dist/cherry-markdown.stream.js 482 kB +88.4 kB (+22.45%) 🚨
packages/cherry-markdown/dist/types/Cherry.d.ts 4.63 kB +129 B (+2.87%)
packages/cherry-markdown/dist/types/core/hooks/Suggester.d.ts 2.21 kB +492 B (+28.55%) 🚨
packages/cherry-markdown/dist/types/Editor.d.ts 5.62 kB +3.64 kB (+183.45%) 🆘
packages/cherry-markdown/dist/types/Factory.d.ts 1.01 kB +34 B (+3.47%)
packages/cherry-markdown/dist/types/Previewer.d.ts 2.78 kB +251 B (+9.94%) ⚠️
packages/cherry-markdown/dist/types/toolbars/Bubble.d.ts 1.01 kB +353 B (+53.73%) 🆘
packages/cherry-markdown/dist/types/toolbars/FloatMenu.d.ts 783 B +206 B (+35.7%) 🚨
packages/cherry-markdown/dist/types/toolbars/hooks/Redo.d.ts 263 B -5 B (-1.87%)
packages/cherry-markdown/dist/types/toolbars/MenuBase.d.ts 2.76 kB +149 B (+5.7%) 🔍
packages/cherry-markdown/dist/types/toolbars/PreviewerBubble.d.ts 2.72 kB +143 B (+5.54%) 🔍
packages/cherry-markdown/dist/types/toolbars/ShortcutKeyConfigPanel.d.ts 1.36 kB -3 B (-0.22%)
packages/cherry-markdown/dist/types/toolbars/Toolbar.d.ts 2.25 kB -35 B (-1.54%)
packages/cherry-markdown/dist/types/utils/autoindent.d.ts 232 B -218 B (-48.44%) 🎉
packages/cherry-markdown/dist/types/utils/cm-search-replace.d.ts 1.75 kB +234 B (+15.39%) ⚠️
packages/cherry-markdown/dist/types/utils/codeBlockContentHandler.d.ts 949 B -376 B (-28.38%) 🎉
packages/cherry-markdown/dist/types/utils/lazyLoadImg.d.ts 2.65 kB +83 B (+3.23%)
packages/cherry-markdown/dist/types/utils/listContentHandler.d.ts 633 B -12 B (-1.86%)
packages/cherry-markdown/dist/types/utils/pasteHelper.d.ts 971 B +214 B (+28.27%) 🚨
packages/cherry-markdown/dist/types/utils/selection.d.ts 0 B -723 B (removed) 🏆
packages/cherry-markdown/dist/types/utils/shortcutKey.d.ts 545 B +6 B (+1.11%)
ℹ️ View Unchanged
Filename Size
packages/cherry-markdown/dist/addons/advance/cherry-codeblock-echarts-plugin.esm.js 29.6 kB
packages/cherry-markdown/dist/addons/advance/cherry-codeblock-echarts-plugin.js 29.7 kB
packages/cherry-markdown/dist/addons/advance/cherry-table-echarts-plugin.esm.js 49.3 kB
packages/cherry-markdown/dist/addons/advance/cherry-table-echarts-plugin.js 49.4 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-checklist-plugin.esm.js 22.4 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-checklist-plugin.js 22.5 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-html-tag-plugin.esm.js 22.3 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-html-tag-plugin.js 22.4 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-table-plugin.esm.js 25.4 kB
packages/cherry-markdown/dist/addons/advance/cherry-tapd-table-plugin.js 25.5 kB
packages/cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin.esm.js 23.2 kB
packages/cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin.js 23.3 kB
packages/cherry-markdown/dist/addons/cherry-code-block-plantuml-plugin.esm.js 24.7 kB
packages/cherry-markdown/dist/addons/cherry-code-block-plantuml-plugin.js 24.8 kB
packages/cherry-markdown/dist/cherry-markdown.core.d.ts 106 B
packages/cherry-markdown/dist/cherry-markdown.d.ts 101 B
packages/cherry-markdown/dist/cherry-markdown.engine.core.d.ts 116 B
packages/cherry-markdown/dist/cherry-markdown.engine.core.esm.d.ts 116 B
packages/cherry-markdown/dist/cherry-markdown.esm.d.ts 101 B
packages/cherry-markdown/dist/cherry-markdown.markdown.css 20.7 kB
packages/cherry-markdown/dist/cherry-markdown.markdown.min.css 14.3 kB
packages/cherry-markdown/dist/cherry-markdown.stream.d.ts 100 B
packages/cherry-markdown/dist/cherry-markdown.stream.esm.d.ts 100 B
packages/cherry-markdown/dist/types/addons/advance/cherry-codeblock-echarts-plugin.d.ts 186 B
packages/cherry-markdown/dist/types/addons/advance/cherry-table-echarts-plugin.d.ts 1.73 kB
packages/cherry-markdown/dist/types/addons/advance/cherry-tapd-checklist-plugin.d.ts 323 B
packages/cherry-markdown/dist/types/addons/advance/cherry-tapd-html-tag-plugin.d.ts 494 B
packages/cherry-markdown/dist/types/addons/advance/cherry-tapd-table-plugin.d.ts 1.15 kB
packages/cherry-markdown/dist/types/addons/cherry-code-block-mermaid-plugin.d.ts 1.37 kB
packages/cherry-markdown/dist/types/addons/cherry-code-block-plantuml-plugin.d.ts 160 B
packages/cherry-markdown/dist/types/Cherry.config.d.ts 122 B
packages/cherry-markdown/dist/types/CherryStatic.d.ts 547 B
packages/cherry-markdown/dist/types/CherryStream.d.ts 1.59 kB
packages/cherry-markdown/dist/types/core/HookCenter.d.ts 816 B
packages/cherry-markdown/dist/types/core/hooks/AiFlowAutoClose.d.ts 370 B
packages/cherry-markdown/dist/types/core/hooks/AutoLink.d.ts 948 B
packages/cherry-markdown/dist/types/core/hooks/BackgroundColor.d.ts 189 B
packages/cherry-markdown/dist/types/core/hooks/Blockquote.d.ts 195 B
packages/cherry-markdown/dist/types/core/hooks/Br.d.ts 193 B
packages/cherry-markdown/dist/types/core/hooks/CodeBlock.d.ts 1.67 kB
packages/cherry-markdown/dist/types/core/hooks/Color.d.ts 183 B
packages/cherry-markdown/dist/types/core/hooks/CommentReference.d.ts 665 B
packages/cherry-markdown/dist/types/core/hooks/Detail.d.ts 328 B
packages/cherry-markdown/dist/types/core/hooks/Emoji.config.d.ts 9.31 kB
packages/cherry-markdown/dist/types/core/hooks/Emoji.d.ts 9.36 kB
packages/cherry-markdown/dist/types/core/hooks/Emphasis.d.ts 263 B
packages/cherry-markdown/dist/types/core/hooks/Footnote.d.ts 307 B
packages/cherry-markdown/dist/types/core/hooks/FrontMatter.d.ts 192 B
packages/cherry-markdown/dist/types/core/hooks/Header.d.ts 605 B
packages/cherry-markdown/dist/types/core/hooks/HighLight.d.ts 158 B
packages/cherry-markdown/dist/types/core/hooks/Hr.d.ts 223 B
packages/cherry-markdown/dist/types/core/hooks/HtmlBlock.d.ts 313 B
packages/cherry-markdown/dist/types/core/hooks/Image.d.ts 325 B
packages/cherry-markdown/dist/types/core/hooks/InlineCode.d.ts 181 B
packages/cherry-markdown/dist/types/core/hooks/InlineMath.d.ts 696 B
packages/cherry-markdown/dist/types/core/hooks/Link.d.ts 583 B
packages/cherry-markdown/dist/types/core/hooks/List.d.ts 347 B
packages/cherry-markdown/dist/types/core/hooks/MathBlock.d.ts 451 B
packages/cherry-markdown/dist/types/core/hooks/Panel.d.ts 435 B
packages/cherry-markdown/dist/types/core/hooks/Paragraph.d.ts 664 B
packages/cherry-markdown/dist/types/core/hooks/Ruby.d.ts 154 B
packages/cherry-markdown/dist/types/core/hooks/Size.d.ts 177 B
packages/cherry-markdown/dist/types/core/hooks/Space.d.ts 199 B
packages/cherry-markdown/dist/types/core/hooks/Strikethrough.d.ts 240 B
packages/cherry-markdown/dist/types/core/hooks/Sub.d.ts 180 B
packages/cherry-markdown/dist/types/core/hooks/SuggestList.d.ts 158 B
packages/cherry-markdown/dist/types/core/hooks/Sup.d.ts 180 B
packages/cherry-markdown/dist/types/core/hooks/Table.d.ts 554 B
packages/cherry-markdown/dist/types/core/hooks/Toc.d.ts 974 B
packages/cherry-markdown/dist/types/core/hooks/Transfer.d.ts 176 B
packages/cherry-markdown/dist/types/core/hooks/Underline.d.ts 157 B
packages/cherry-markdown/dist/types/core/HooksConfig.d.ts 524 B
packages/cherry-markdown/dist/types/core/ParagraphBase.d.ts 1.38 kB
packages/cherry-markdown/dist/types/core/SyntaxBase.d.ts 955 B
packages/cherry-markdown/dist/types/Engine.d.ts 1.53 kB
packages/cherry-markdown/dist/types/Event.d.ts 531 B
packages/cherry-markdown/dist/types/index.core.d.ts 122 B
packages/cherry-markdown/dist/types/index.d.ts 76 B
packages/cherry-markdown/dist/types/index.engine.core.d.ts 376 B
packages/cherry-markdown/dist/types/index.engine.d.ts 87 B
packages/cherry-markdown/dist/types/index.stream.d.ts 107 B
packages/cherry-markdown/dist/types/libs/rawdeflate.d.ts 87 B
packages/cherry-markdown/dist/types/locales/en_US.d.ts 1.11 kB
packages/cherry-markdown/dist/types/locales/index.d.ts 141 B
packages/cherry-markdown/dist/types/locales/ru_RU.d.ts 1.11 kB
packages/cherry-markdown/dist/types/locales/zh_CN.d.ts 1.12 kB
packages/cherry-markdown/dist/types/Logger.d.ts 441 B
packages/cherry-markdown/dist/types/Sanitizer.d.ts 85 B
packages/cherry-markdown/dist/types/toolbars/BubbleFormula.d.ts 1.38 kB
packages/cherry-markdown/dist/types/toolbars/BubbleTable.d.ts 329 B
packages/cherry-markdown/dist/types/toolbars/HiddenToolbar.d.ts 226 B
packages/cherry-markdown/dist/types/toolbars/HookCenter.d.ts 508 B
packages/cherry-markdown/dist/types/toolbars/hooks/Align.d.ts 191 B
packages/cherry-markdown/dist/types/toolbars/hooks/Audio.d.ts 322 B
packages/cherry-markdown/dist/types/toolbars/hooks/Bold.d.ts 455 B
packages/cherry-markdown/dist/types/toolbars/hooks/Br.d.ts 318 B
packages/cherry-markdown/dist/types/toolbars/hooks/ChangeLocale.d.ts 252 B
packages/cherry-markdown/dist/types/toolbars/hooks/CheckList.d.ts 353 B
packages/cherry-markdown/dist/types/toolbars/hooks/Code.d.ts 398 B
packages/cherry-markdown/dist/types/toolbars/hooks/CodeTheme.d.ts 451 B
packages/cherry-markdown/dist/types/toolbars/hooks/Color.d.ts 2.11 kB
packages/cherry-markdown/dist/types/toolbars/hooks/Copy.d.ts 697 B
packages/cherry-markdown/dist/types/toolbars/hooks/CursorPosition.d.ts 207 B
packages/cherry-markdown/dist/types/toolbars/hooks/Detail.d.ts 324 B
packages/cherry-markdown/dist/types/toolbars/hooks/DrawIo.d.ts 421 B
packages/cherry-markdown/dist/types/toolbars/hooks/Export.d.ts 195 B
packages/cherry-markdown/dist/types/toolbars/hooks/File.d.ts 319 B
packages/cherry-markdown/dist/types/toolbars/hooks/Formula.d.ts 459 B
packages/cherry-markdown/dist/types/toolbars/hooks/FullScreen.d.ts 206 B
packages/cherry-markdown/dist/types/toolbars/hooks/Graph.d.ts 736 B
packages/cherry-markdown/dist/types/toolbars/hooks/H1.d.ts 390 B
packages/cherry-markdown/dist/types/toolbars/hooks/H2.d.ts 391 B
packages/cherry-markdown/dist/types/toolbars/hooks/H3.d.ts 391 B
packages/cherry-markdown/dist/types/toolbars/hooks/Header.d.ts 505 B
packages/cherry-markdown/dist/types/toolbars/hooks/Hr.d.ts 322 B
packages/cherry-markdown/dist/types/toolbars/hooks/Image.d.ts 345 B
packages/cherry-markdown/dist/types/toolbars/hooks/InlineCode.d.ts 429 B
packages/cherry-markdown/dist/types/toolbars/hooks/Insert.d.ts 473 B
packages/cherry-markdown/dist/types/toolbars/hooks/Italic.d.ts 464 B
packages/cherry-markdown/dist/types/toolbars/hooks/Justify.d.ts 163 B
packages/cherry-markdown/dist/types/toolbars/hooks/Link.d.ts 347 B
packages/cherry-markdown/dist/types/toolbars/hooks/List.d.ts 486 B
packages/cherry-markdown/dist/types/toolbars/hooks/MobilePreview.d.ts 316 B
packages/cherry-markdown/dist/types/toolbars/hooks/Ol.d.ts 349 B
packages/cherry-markdown/dist/types/toolbars/hooks/Panel.d.ts 475 B
packages/cherry-markdown/dist/types/toolbars/hooks/Pdf.d.ts 318 B
packages/cherry-markdown/dist/types/toolbars/hooks/ProTable.d.ts 561 B
packages/cherry-markdown/dist/types/toolbars/hooks/Publish.d.ts 388 B
packages/cherry-markdown/dist/types/toolbars/hooks/QuickTable.d.ts 441 B
packages/cherry-markdown/dist/types/toolbars/hooks/Quote.d.ts 245 B
packages/cherry-markdown/dist/types/toolbars/hooks/Ruby.d.ts 447 B
packages/cherry-markdown/dist/types/toolbars/hooks/Search.d.ts 369 B
packages/cherry-markdown/dist/types/toolbars/hooks/Settings.d.ts 752 B
packages/cherry-markdown/dist/types/toolbars/hooks/ShortcutKey.d.ts 442 B
packages/cherry-markdown/dist/types/toolbars/hooks/Size.d.ts 301 B
packages/cherry-markdown/dist/types/toolbars/hooks/Split.d.ts 319 B
packages/cherry-markdown/dist/types/toolbars/hooks/Strikethrough.d.ts 404 B
packages/cherry-markdown/dist/types/toolbars/hooks/Sub.d.ts 372 B
packages/cherry-markdown/dist/types/toolbars/hooks/Sup.d.ts 372 B
packages/cherry-markdown/dist/types/toolbars/hooks/SwitchModel.d.ts 285 B
packages/cherry-markdown/dist/types/toolbars/hooks/Table.d.ts 364 B
packages/cherry-markdown/dist/types/toolbars/hooks/Theme.d.ts 465 B
packages/cherry-markdown/dist/types/toolbars/hooks/Toc.d.ts 320 B
packages/cherry-markdown/dist/types/toolbars/hooks/TogglePreview.d.ts 340 B
packages/cherry-markdown/dist/types/toolbars/hooks/Ul.d.ts 350 B
packages/cherry-markdown/dist/types/toolbars/hooks/Underline.d.ts 404 B
packages/cherry-markdown/dist/types/toolbars/hooks/Undo.d.ts 245 B
packages/cherry-markdown/dist/types/toolbars/hooks/Video.d.ts 322 B
packages/cherry-markdown/dist/types/toolbars/hooks/Word.d.ts 318 B
packages/cherry-markdown/dist/types/toolbars/hooks/WordCount.d.ts 376 B
packages/cherry-markdown/dist/types/toolbars/Sidebar.d.ts 224 B
packages/cherry-markdown/dist/types/toolbars/Toc.d.ts 390 B
packages/cherry-markdown/dist/types/toolbars/ToolbarRight.d.ts 156 B
packages/cherry-markdown/dist/types/UrlCache.d.ts 529 B
packages/cherry-markdown/dist/types/utils/async-render-handler.d.ts 344 B
packages/cherry-markdown/dist/types/utils/code-preview-language-setting.d.ts 169 B
packages/cherry-markdown/dist/types/utils/color.d.ts 205 B
packages/cherry-markdown/dist/types/utils/config.d.ts 984 B
packages/cherry-markdown/dist/types/utils/copy.d.ts 577 B
packages/cherry-markdown/dist/types/utils/dialog.d.ts 195 B
packages/cherry-markdown/dist/types/utils/dom.d.ts 650 B
packages/cherry-markdown/dist/types/utils/downloadUtil.d.ts 426 B
packages/cherry-markdown/dist/types/utils/env.d.ts 482 B
packages/cherry-markdown/dist/types/utils/error.d.ts 185 B
packages/cherry-markdown/dist/types/utils/event.d.ts 440 B
packages/cherry-markdown/dist/types/utils/export.d.ts 422 B
packages/cherry-markdown/dist/types/utils/exportWord.d.ts 424 B
packages/cherry-markdown/dist/types/utils/file.d.ts 848 B
packages/cherry-markdown/dist/types/utils/footnoteHoverHandler.d.ts 889 B
packages/cherry-markdown/dist/types/utils/formulaUtilsHandler.d.ts 637 B
packages/cherry-markdown/dist/types/utils/htmlparser.d.ts 1.67 kB
packages/cherry-markdown/dist/types/utils/image.d.ts 454 B
packages/cherry-markdown/dist/types/utils/imgSizeHandler.d.ts 974 B
packages/cherry-markdown/dist/types/utils/imgToolHandler.d.ts 333 B
packages/cherry-markdown/dist/types/utils/lineFeed.d.ts 720 B
packages/cherry-markdown/dist/types/utils/lookbehind-replace.d.ts 381 B
packages/cherry-markdown/dist/types/utils/LRUCache.d.ts 554 B
packages/cherry-markdown/dist/types/utils/mathjax.d.ts 218 B
packages/cherry-markdown/dist/types/utils/myersDiff.d.ts 906 B
packages/cherry-markdown/dist/types/utils/platformTransform.d.ts 151 B
packages/cherry-markdown/dist/types/utils/recount-pos.d.ts 259 B
packages/cherry-markdown/dist/types/utils/regexp.d.ts 1.58 kB
packages/cherry-markdown/dist/types/utils/sanitize.d.ts 423 B
packages/cherry-markdown/dist/types/utils/svgUtils.d.ts 650 B
packages/cherry-markdown/dist/types/utils/tableContentHandler.d.ts 3.24 kB

compressed-size-action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the Cherry Markdown editor from CodeMirror 5.58.2 to CodeMirror 6.0.1+, introducing a comprehensive compatibility layer (CM6Adapter) to maintain backward compatibility with the existing API while leveraging the new architecture.

Key changes:

  • Complete replacement of CodeMirror 5 with CodeMirror 6 modular packages
  • Implementation of CM6Adapter class providing CM5-compatible API surface
  • Migration of all editor-related utilities and components to CM6 APIs
  • Updates to event handling, selection management, and DOM interactions

Reviewed changes

Copilot reviewed 44 out of 49 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package.json Replaces CM5 dependencies with CM6 modular packages, upgrades TypeScript to 5.7.3
types/editor.d.ts Adds CM6Adapter interface with comprehensive API compatibility definitions
types/codemirror.d.ts Replaces CM5 type extensions with CM6LineBlock interface
types/cherry.d.ts Updates editor type from CM5 Editor to CM6 EditorView
src/Editor.js Implements CM6Adapter class, migrates to CM6 APIs, adds custom syntax highlighter
src/Cherry.js Updates all editor interactions to use CM6 APIs through adapter
src/Previewer.js Adjusts scrolling logic and editor refresh calls for CM6
src/utils/selection.js Rewrites selection utilities using CM6 state/transaction APIs
src/utils/shortcutKey.js Removes CM5 browser util dependency, implements platform detection
src/utils/regexp.js Refactors regex construction to avoid backreference issues
src/utils/pasteHelper.js Updates DOM queries and event handling for CM6
src/utils/file.js Changes from doc.replaceSelection to adapter.replaceSelection
src/utils/autoindent.js Adapts list autoindent logic for CM6Adapter
src/toolbars/MenuBase.js Comprehensive rewrite of selection/cursor manipulation for CM6
src/toolbars/hooks/* Updates all toolbar hooks to use CM6 state.doc.sliceString
src/toolbars/Bubble.js Migrates to CM6 DOM structure (.cm-editor) and coordsAtPos API
src/toolbars/FloatMenu.js Creates compatibility layer for cursor activity events
src/toolbars/Toolbar.js Simplifies toolbar visibility methods
src/toolbars/Toc.js Switches from CM5 events to Cherry event system
src/core/hooks/Suggester.js Updates panel positioning using CM6 coordsAtPos
src/sass/*.scss Updates CSS selectors from .CodeMirror-* to .cm-*
yarn.lock Adds CM6 package dependencies and removes CM5

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/Editor.js Outdated
Comment thread packages/cherry-markdown/src/Editor.js Outdated
@RSS1102 RSS1102 marked this pull request as draft January 2, 2026 18:55
@RSS1102
Copy link
Copy Markdown
Collaborator Author

RSS1102 commented Jan 2, 2026

CodeMirror 5 → 6 参考以下进行未来测试覆盖

✅ 核心 API 功能列表

文档操作

API 状态 说明
getValue() 获取完整文档内容
setValue(text) 设置文档内容
getLine(line) 获取指定行内容
lineCount() 获取总行数
replaceRange(text, from, to) 替换指定范围文本
getRange(from, to) 获取范围内文本

选择操作

API 状态 说明
getSelection() 获取选中文本
getSelections() 获取多选文本数组
replaceSelection(text) 替换选中文本
replaceSelections(texts) 批量替换多选文本
setSelection(from, to) 设置选择范围
listSelections() 获取所有选择范围

光标操作

API 状态 说明
getCursor(type) 获取光标位置
setCursor(line, ch) 设置光标位置
cursorCoords(where) 获取光标坐标

坐标转换

API 状态 说明
posToLineAndCh(pos) 位置转行列号
lineAndChToPos(line, ch) 行列号转位置
posAtCoords(coords) 坐标转位置

滚动操作

API 状态 说明
scrollTo(x, y) 滚动到指定位置
scrollIntoView(pos) 滚动到指定位置可见
getScrollInfo() 获取滚动信息

搜索功能

API 状态 说明
setSearchQuery(query) 搜索并高亮
clearSearchQuery() 清除搜索高亮

标记功能

API 状态 说明
markText(from, to, options) 标记文本范围
findMarks(from, to) 查找范围内标记

DOM 操作

API 状态 说明
getWrapperElement() 获取包装元素
getScrollerElement() 获取滚动元素
refresh() 刷新编辑器
focus() 聚焦编辑器

🎬 事件系统

事件名 状态 触发时机
blur 编辑器失焦
focus 编辑器聚焦
change 文档内容改变
scroll 编辑器滚动
paste 粘贴内容
mousedown 鼠标按下
keydown 按键按下
keyup 按键释放
cursorActivity 光标位置改变
beforeChange 内容即将改变
drop 拖放内容

⚙️ 编辑器配置

支持的配置项

配置项 状态 说明
lineNumbers 是否显示行号
placeholder 占位符文本
autofocus 自动聚焦
keyMap 键盘映射风格(sublime/vim)
lineWrapping 自动换行

⌨️ 键盘快捷键

Sublime 风格快捷键 (默认)

通过以下 keymap 组合实现:

  • defaultKeymap - 基础编辑快捷键
  • historyKeymap - 撤销/重做
  • closeBracketsKeymap - 括号自动闭合
  • searchKeymap - 搜索相关
  • indentWithTab - Tab 缩进

支持的快捷键:

  • Ctrl+[ / Ctrl+] - 减少/增加缩进
  • Ctrl+Shift+D - 复制当前行
  • Ctrl+Enter - 在下方插入行
  • Ctrl+Shift+Enter - 在上方插入行
  • Ctrl+Shift+↑ / Ctrl+Shift+↓ - 向上/下移动行
  • Ctrl+Shift+K - 删除当前行
  • Ctrl+Shift+← / Ctrl+Shift+→ - 选择到行首/行尾
  • Ctrl+Backspace - 删除到单词开始
  • Ctrl+Shift+M - 选择匹配的括号内容
  • Ctrl+Shift+L - 在多个位置插入光标
  • Alt+F3 - 选择所有匹配项
  • Ctrl+Z / Ctrl+Y - 撤销/重做

Vim 模式

支持完整的 Vim 键位,可通过配置或运行时切换。


🎨 语法高亮

支持的语法元素:

  • 字符串、数字、关键字
  • 注释、标题、强调
  • 链接、代码块
  • 列表、引用
  • 全角符号高亮

🔧 已修复的问题

  • ✅ autofocus 配置支持
  • ✅ 移除 extraKeys 残留
  • ✅ 清理注释的 CM5 代码

📦 依赖变化

  • ✅ 已完全移除 CodeMirror 5
  • ✅ 已升级到 CodeMirror 6
  • ✅ 支持 Vim 模式 (@replit/codemirror-vim)

🏗️ 架构改进

  • ✅ 使用 CM6Adapter 适配器层提供 API 兼容
  • ✅ 通过 StateField 和 StateEffect 管理状态
  • ✅ 支持搜索高亮、文本标记、键盘映射等功能

✨ 新增功能

  • ✅ Vim 模式支持,可动态切换
  • ✅ 改进的搜索高亮
  • ✅ 更好的快捷键管理
  • ✅ 完整的 TypeScript 类型定义

🧪 测试建议

功能测试

  • 文档编辑(输入、删除、替换)
  • 选择操作(单选、多选)
  • 光标移动(键盘、鼠标)
  • 搜索和替换
  • 撤销/重做
  • 复制/粘贴
  • 快捷键(Sublime 和 Vim)
  • 全角符号高亮
  • 自动聚焦

性能测试

  • 大文档加载(10000+ 行)
  • 快速输入响应
  • 滚动流畅度
  • 搜索性能

兼容性测试

  • Chrome
  • Firefox
  • Safari
  • Edge

📚 相关资源

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 50 out of 55 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/toolbars/hooks/H1.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/hooks/Bold.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/FloatMenu.js Outdated
Comment thread packages/cherry-markdown/src/core/hooks/Suggester.js Outdated
Comment thread packages/cherry-markdown/src/Editor.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 54 out of 59 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/toolbars/hooks/Bold.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/hooks/Bold.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/FloatMenu.js Outdated
Comment thread packages/cherry-markdown/src/core/hooks/Suggester.js Outdated
Comment thread examples/vim.html Outdated
@tencent-adm
Copy link
Copy Markdown
Member

tencent-adm commented Jan 7, 2026

CLA assistant check
All committers have signed the CLA.

@RSS1102 RSS1102 changed the title refactor: migrate to Codemirror @6 and update editor functionalities refactor: migrate to Codemirror@6 and update editor functionalities Jan 8, 2026
@RSS1102 RSS1102 added the minor 破坏性更改,break change label Jan 9, 2026
@RSS1102 RSS1102 force-pushed the upgrade_codemirror_v6_251213 branch from 4dd9303 to ef26ae6 Compare March 10, 2026 08:50
@RSS1102 RSS1102 requested a review from Copilot March 11, 2026 09:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 65 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/toolbars/Toolbar.js
Comment thread packages/cherry-markdown/src/toolbars/MenuBase.js
Comment thread packages/cherry-markdown/src/utils/cm-search-replace.js Outdated
Comment thread packages/cherry-markdown/src/utils/codeBlockContentHandler.js
Comment thread packages/cherry-markdown/src/toolbars/hooks/CursorPosition.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/PreviewerBubble.js Outdated
Comment thread packages/cherry-markdown/src/utils/file.js
Comment thread packages/cherry-markdown/src/toolbars/Bubble.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/FloatMenu.js
Comment thread packages/cherry-markdown/src/sass/cherry.scss Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 65 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/utils/codeBlockContentHandler.js Outdated
Comment thread packages/cherry-markdown/src/toolbars/MenuBase.js
Comment thread packages/cherry-markdown/src/utils/listContentHandler.js
Comment thread packages/cherry-markdown/src/toolbars/Bubble.js Outdated
Comment thread packages/cherry-markdown/src/utils/autoindent.js
Comment thread packages/cherry-markdown/src/Cherry.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 60 out of 65 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/cherry-markdown/src/toolbars/MenuBase.js Outdated
Comment thread packages/cherry-markdown/src/utils/cm-search-replace.js Outdated
Comment thread packages/cherry-markdown/src/utils/autoindent.js Outdated
@RSS1102 RSS1102 marked this pull request as ready for review March 24, 2026 09:58
@RSS1102 RSS1102 merged commit c2b9e9e into dev Apr 3, 2026
12 checks passed
@RSS1102 RSS1102 deleted the upgrade_codemirror_v6_251213 branch April 3, 2026 07:37
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

📦 cherry-markdown dev preview published

⚠️ 注意: 此版本为开发预览版,禁止在生产环境使用!

此方式引用代码中仍然可以使用 cherry-markdown 包名,不需要修改现有的 import 语句

⚠️ Note: This version is a developer preview and should not be used in production environments!

This way of referencing allows you to still use the package name cherry-markdown, no need to modify existing import statements

Install NPM with :

pnpm add cherry-markdown@npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e
yarn add cherry-markdown@npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e
npm i cherry-markdown@npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e

如果你使用了其他以 cherry-markdown 作为同等依赖(peer dependency)的元框架,你需要在 package.json 文件中覆盖 cherry-markdown 依赖,具体操作方式会因你使用的包管理器而略有不同

If you use a meta framework that has cherry-markdown as peer dependency, you have to override the cherry-markdown dependency in your package.json, which works slightly different depending on your package manager

# npm
{
  "overrides": {
    "cherry-markdown": "npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e"
  }
}
# yarn
{
  "resolutions": {
    "cherry-markdown": "npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e"
  }
}
# pnpm
{
  "pnpm": {
    "overrides": {
      "cherry-markdown": "npm:@cherry-markdown/cherry-markdown-dev@0.11.0-alpha-5-202604030738.c2b9e9e"
    }
  }
}

在添加 overrides 之后,重新安装你的依赖并像往常一样启动你的开发服务器或构建你的项目即可,无需进一步的配置更改

After adding these overrides, reinstall your dependencies and start your development server or build your project as usual. No further configuration changes are required

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

💻 Cherry-Markdown Client 预览构建已完成

平台 架构 产物类型 下载
Linux x64 AppImage 下载
Linux x64 Deb 包 下载
macOS Apple Silicon DMG 安装包 下载
macOS Apple Silicon App 应用 下载
macOS x64 DMG 安装包 下载
macOS x64 App 应用 下载
Windows x64 MSI 安装包 下载
Windows x64 EXE 安装程序 下载

📋 版本: 0.2.1 | ⏰ 产物保留 7 天 | 查看所有构建产物

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

Labels

minor 破坏性更改,break change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

升级codemirror

5 participants