feat: 支持安全的 Markdown 块拖拽重排 - #346
Draft
jackson-zhou wants to merge 2 commits into
Draft
jackson-zhou wants to merge 2 commits into
jackson-zhou wants to merge 2 commits into
Conversation
|
|
This branch has not been deployed
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.
摘要
新增可选的 Markdown 块重排插件:通过拖拽手柄移动一个完整的最外层块,保留原始源码和 Markdown 结构,并支持一步撤销。源码模式和实时预览模式共用同一套移动规划逻辑。
**贡献说明:**实现、测试和文档主要由 AI 生成,已完成代码审查、自动化测试及真实浏览器和 Electron 验证。OpenSpec 提案、仓库贡献政策审核及剩余人工验收仍待完成,暂保留 Draft;AI 使用情况和待确认事项在下方如实列明。
背景与动机
Closes #332。本 PR 基于
main独立实现,作为与 #331 并列的另一种实现方案供审查。变更内容
packages/plugin-block-drag:提供可选的 legacy 插件工厂和原生生命周期插件;实现拖动启动阈值、源块高亮、插入位置提示、边缘自动滚动、取消、手柄键盘导航,以及只读、输入法组合输入和折叠状态保护。横向滚动长代码时,手柄与提示保持在可视内容区域。原生运行时中的移动命令由宿主命令服务统一管理,支持改键、清除快捷键、冲突处理、当前编辑器路由和卸载。packages/core:新增prepareBlockMove(view),在表格失焦前捕获待提交输入,核实宿主是否原样接受输入,并保留被拒绝的编辑以便重试。多个待提交表格按源码位置从后向前提交。已接受的单元格编辑与块移动拥有独立的撤销边界。如果保存表格改变了块结构,则保留保存结果并取消移动,避免使用失效索引移动错误内容。宿主重建事务时保留历史记录元数据。packages/reference-plugins、apps/electron-demo:增加可选启动开关,在 demo 的两种接入模式下默认启用,并将插件以零权限需求登记到内置插件名单。openspec/与文档:补充设计、API 契约、明确的范围限制、可复跑的浏览器/Electron 冒烟测试脚本、验证记录和剩余验收清单。每次只移动一个最外层块;标题只移动自身,不带走下方章节内容,图片随所属段落移动。首版不支持触屏、多块或跨文档移动,以及列表内部排序和嵌套调整。
测试与验证
pnpm test:72 个测试文件、1,043 项测试通过。pnpm typecheck、pnpm check:api、pnpm build、pnpm build:electron-demo均通过。pnpm --filter @floatboat/nexus-electron-demo smoke:multi-window通过。pnpm dlx @fission-ai/openspec validate add-markdown-block-reordering --strict通过。已知基线限制:连续操作两个编辑器时,第二个编辑器的块移动后选区可能回到文首;纯 CodeMirror(不加载 Nexus 或此插件)同样能复现。本 PR 未修改该行为,runtime 路由验收按独立命令用例显式选择起始块,详细复现与对照见验证记录。
验证环境:macOS 26.6.2 arm64;Chrome 152.0.7977.84;Electron 35.7.5;Playwright 1.55.0;Node 23.7.0;pnpm 9.15.4。以上结果来自本地验证,上游 CI 状态另行确认。
合规自检
playwright@1.55.0,许可证为 Apache-2.0,用于可复跑的真实浏览器与 Electron 验收,不加入插件运行时依赖。自检清单
截图
拖动过程中:第一段高亮,目标插入位置位于第三段之后。
释放后:第一段移动到文末。