feat: 阶段1-3 桌面编辑器(Tauri 骨架/编辑核心深化/复杂内容)

This commit is contained in:
Muse
2026-11-13 21:19:23 +08:00
parent cbd7ce4b44
commit cbe641e21a
36 changed files with 10059 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
// 阶段门禁(架构 §7):阶段 0 的往返稳定性套件在正式工程上必须继续全绿。
import { describe, it, expect, afterEach } from 'vitest'
import type { Editor } from '@milkdown/kit/core'
import { createMarkdownEditor, getMarkdown, callUndo } from '../src/editor/editor'
const SAMPLE = `# 标题
包含**粗体**与任务:
- [ ] 待办
- [x] 完成
| 列一 | 列二 |
| :--- | ---: |
| 甲 | 1 |
\`\`\`ts
const n = 1;
\`\`\`
`
let editors: Editor[] = []
afterEach(async () => {
for (const e of editors) { try { await e.destroy() } catch { /* ignore */ } }
editors = []
document.body.innerHTML = ''
})
async function load(md: string): Promise<Editor> {
const root = document.createElement('div')
document.body.appendChild(root)
const editor = createMarkdownEditor(root, md)
editors.push(editor)
await editor.create()
return editor
}
describe('编辑器回归(阶段 0 套件)', () => {
it('往返保真且第二轮逐字稳定', async () => {
const once = getMarkdown(await load(SAMPLE))
expect(once).toContain('**粗体**')
expect(once).toMatch(/-\s\[ \]\s待办/)
expect(once).toMatch(/-\s\[[xX]\]\s完成/)
expect(once).toContain('甲')
const twice = getMarkdown(await load(once))
expect(twice).toBe(once)
})
it('撤销命令仍可用', async () => {
const editor = await load('原文\n')
const { editorViewCtx } = await import('@milkdown/kit/core')
editor.action((ctx) => {
const view = ctx.get(editorViewCtx)
view.dispatch(view.state.tr.insertText('X', view.state.doc.content.size))
})
expect(getMarkdown(editor)).toContain('X')
callUndo(editor)
expect(getMarkdown(editor)).not.toContain('X')
})
})