fix(editor): 新建文档自动聚焦 + 空文档占位 + 编辑面填满(docs/23)

新建/打开/恢复的标签就绪后自动把光标送进编辑器(弹窗/查找栏打开时
不抢);切回标签恢复锚点时一并聚焦。空文档首段显示「开始输入…」
占位。编辑面改为撑满窗格高度,下方空白处可点击落光标;host 显式
width:100% 防 flex 收缩窄缝。
This commit is contained in:
Muse
2026-11-14 16:06:27 +08:00
parent d637f0a849
commit c0f03e48dc
6 changed files with 120 additions and 10 deletions

View File

@@ -0,0 +1,29 @@
// 空文档占位:空文档首段挂 .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()
})
})