fix(desktop): 重构菜单并恢复 Shiki 高亮

This commit is contained in:
2026-09-07 23:35:43 +08:00
parent 078aabc667
commit cb123f4317
9 changed files with 315 additions and 100 deletions
@@ -1,5 +1,5 @@
import { afterEach, expect, it, vi } from 'vitest'
import { executeEditorCommand, registerEditorCommands, getEditorCommandCapabilities } from './editorCommandService'
import { executeEditorCommand, registerEditorCommands, getEditorCommandCapabilities, subscribeEditorCommandCapabilities, updateNativeEditorMenu } from './editorCommandService'
let dispose: (() => void) | undefined
afterEach(() => dispose?.())
it('reports unsupported, disabled and invalid commands without side effects', async () => {
@@ -23,3 +23,14 @@ it('old editor disposal cannot unregister the replacement editor', async () => {
dispose()
expect(await executeEditorCommand('editor.bold')).toEqual({ ok: false, reason: 'unavailable' })
})
it('notifies the visible menu when the active editor capability changes', () => {
const listener = vi.fn()
const unsubscribe = subscribeEditorCommandCapabilities(listener)
dispose = registerEditorCommands({ available: () => true, handlers: { 'editor.bold': () => ({ ok: true }) } })
expect(listener).toHaveBeenCalledTimes(1)
updateNativeEditorMenu()
expect(listener).toHaveBeenCalledTimes(2)
unsubscribe()
updateNativeEditorMenu()
expect(listener).toHaveBeenCalledTimes(2)
})