fix(desktop): 扩充应用菜单与元数据快捷键
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { executeEditorCommand, registerEditorCommands, getEditorCommandCapabilities, subscribeEditorCommandCapabilities, updateNativeEditorMenu } from './editorCommandService'
|
||||
const hostInvoke = vi.hoisted(() => vi.fn(() => Promise.resolve()))
|
||||
vi.mock('./platform/desktop', () => ({ isDesktop: () => true, hostInvoke }))
|
||||
let dispose: (() => void) | undefined
|
||||
beforeEach(() => hostInvoke.mockClear())
|
||||
afterEach(() => dispose?.())
|
||||
it('reports unsupported, disabled and invalid commands without side effects', async () => {
|
||||
expect(await executeEditorCommand('editor.bold')).toEqual({ ok: false, reason: 'unavailable' })
|
||||
@@ -34,3 +37,7 @@ it('notifies the visible menu when the active editor capability changes', () =>
|
||||
updateNativeEditorMenu()
|
||||
expect(listener).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
it('keeps the native metadata accelerator enabled in writing mode', () => {
|
||||
dispose = registerEditorCommands({ available: () => true, handlers: { 'editor.metadata.edit': () => ({ ok: true }) } })
|
||||
expect(hostInvoke).toHaveBeenLastCalledWith('editor_capabilities', { metadataEnabled: true })
|
||||
})
|
||||
|
||||
@@ -35,7 +35,9 @@ export function registerEditorCommands(target: Target) {
|
||||
}
|
||||
export function updateNativeEditorMenu() {
|
||||
notifyCapabilityListeners()
|
||||
if (isDesktop()) void hostInvoke('editor_capabilities', { importEnabled: !!active?.handlers['editor.import-note-properties'] && active.available() }).catch(() => undefined)
|
||||
const metadataEnabled = !!active?.available()
|
||||
&& (!!active.handlers['editor.import-note-properties'] || !!active.handlers['editor.metadata.edit'])
|
||||
if (isDesktop()) void hostInvoke('editor_capabilities', { metadataEnabled }).catch(() => undefined)
|
||||
}
|
||||
export function getEditorCommandCapabilities() {
|
||||
return editorCommandIds.map(id => ({ id, supported: !!active?.handlers[id], enabled: !!active?.handlers[id] && active.available() }))
|
||||
|
||||
Reference in New Issue
Block a user