Files
new-markdown/tests/empty-placeholder.test.ts
Muse c0f03e48dc fix(editor): 新建文档自动聚焦 + 空文档占位 + 编辑面填满(docs/23)
新建/打开/恢复的标签就绪后自动把光标送进编辑器(弹窗/查找栏打开时
不抢);切回标签恢复锚点时一并聚焦。空文档首段显示「开始输入…」
占位。编辑面改为撑满窗格高度,下方空白处可点击落光标;host 显式
width:100% 防 flex 收缩窄缝。
2026-11-14 16:06:27 +08:00

30 lines
1.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 空文档占位:空文档首段挂 .doc-placeholder(CSS 显示「开始输入…」),有内容时不挂。
import { describe, it, expect, afterEach } from 'vitest'
import type { Editor } from '@milkdown/kit/core'
import { createMarkdownEditor } from '../src/editor/editor'
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<HTMLElement> {
const root = document.createElement('div')
document.body.appendChild(root)
const editor = createMarkdownEditor(root, md)
editors.push(editor)
await editor.create()
return root
}
describe('空文档占位', () => {
it('空文档有占位类,非空文档没有', async () => {
const emptyRoot = await load('')
expect(emptyRoot.querySelector('.doc-placeholder')).not.toBeNull()
const filledRoot = await load('# 标题\n\n正文')
expect(filledRoot.querySelector('.doc-placeholder')).toBeNull()
})
})