- Bind Mod-Shift-z to redo on all platforms (CodeMirror only binds it on Linux/macOS) - Render tables based on editor focus so a note starting with a table is not shown as source - Send the save request without waiting for the IndexedDB draft write, and flush on pagehide; Firefox could drop the last edit when a tab was closed right after typing - Fall back to clipboardData.items when pasting images with an empty files list
21 lines
1001 B
TypeScript
21 lines
1001 B
TypeScript
// @vitest-environment happy-dom
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
describe('快捷键', () => {
|
|
it('Windows 上 Ctrl+Shift+Z 为重做', async () => {
|
|
// CodeMirror 在模块加载时读取平台,需先设置再导入
|
|
Object.defineProperty(navigator, 'platform', { value: 'Win32', configurable: true })
|
|
const { undo } = await import('@codemirror/commands')
|
|
const { EditorView, runScopeHandlers } = await import('@codemirror/view')
|
|
const { createEditorState } = await import('./index')
|
|
const view = new EditorView({ parent: document.body, state: createEditorState({ doc: '' }) })
|
|
view.dispatch({ changes: { from: 0, insert: 'abc' } })
|
|
undo(view)
|
|
expect(view.state.doc.toString()).toBe('')
|
|
const event = new KeyboardEvent('keydown', { key: 'Z', code: 'KeyZ', keyCode: 90, ctrlKey: true, shiftKey: true })
|
|
expect(runScopeHandlers(view, event, 'editor')).toBe(true)
|
|
expect(view.state.doc.toString()).toBe('abc')
|
|
view.destroy()
|
|
})
|
|
})
|