🎨 binding keymap and extension
This commit is contained in:
@@ -5,6 +5,7 @@ import {EditorState, Extension} from '@codemirror/state';
|
||||
import {useConfigStore} from './configStore';
|
||||
import {useDocumentStore} from './documentStore';
|
||||
import {useThemeStore} from './themeStore';
|
||||
import {useKeybindingStore} from './keybindingStore';
|
||||
import {SystemThemeType} from '@/../bindings/voidraft/internal/models/models';
|
||||
import {DocumentService, ExtensionService} from '@/../bindings/voidraft/internal/services';
|
||||
import {ensureSyntaxTree} from "@codemirror/language"
|
||||
@@ -14,7 +15,7 @@ import {getTabExtensions, updateTabConfig} from '@/views/editor/basic/tabExtensi
|
||||
import {createFontExtensionFromBackend, updateFontConfig} from '@/views/editor/basic/fontExtension';
|
||||
import {createStatsUpdateExtension} from '@/views/editor/basic/statsExtension';
|
||||
import {createAutoSavePlugin, createSaveShortcutPlugin} from '@/views/editor/basic/autoSaveExtension';
|
||||
import {createDynamicKeymapExtension} from '@/views/editor/keymap';
|
||||
import {createDynamicKeymapExtension, updateKeymapExtension} from '@/views/editor/keymap';
|
||||
import {createDynamicExtensions, getExtensionManager, setExtensionManagerView} from '@/views/editor/manager';
|
||||
import {useExtensionStore} from './extensionStore';
|
||||
|
||||
@@ -271,18 +272,31 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
await ExtensionService.UpdateExtensionState(id, enabled, config)
|
||||
}
|
||||
|
||||
// 更新前端编辑器
|
||||
// 更新前端编辑器扩展
|
||||
const manager = getExtensionManager()
|
||||
if (manager) {
|
||||
manager.updateExtension(id, enabled, config || {})
|
||||
}
|
||||
|
||||
// 重新加载扩展配置
|
||||
await extensionStore.loadExtensions()
|
||||
|
||||
// 更新快捷键映射
|
||||
if (editorView.value) {
|
||||
updateKeymapExtension(editorView.value)
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 监听扩展状态变化,自动更新快捷键
|
||||
watch(() => extensionStore.enabledExtensions.length, () => {
|
||||
if (editorView.value) {
|
||||
updateKeymapExtension(editorView.value)
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
// 状态
|
||||
documentStats,
|
||||
|
@@ -12,6 +12,11 @@ export const useExtensionStore = defineStore('extension', () => {
|
||||
extensions.value.filter(ext => ext.enabled)
|
||||
)
|
||||
|
||||
// 获取启用的扩展ID列表
|
||||
const enabledExtensionIds = computed(() =>
|
||||
enabledExtensions.value.map(ext => ext.id)
|
||||
)
|
||||
|
||||
/**
|
||||
* 从后端加载扩展配置
|
||||
*/
|
||||
@@ -35,9 +40,10 @@ export const useExtensionStore = defineStore('extension', () => {
|
||||
// 状态
|
||||
extensions,
|
||||
enabledExtensions,
|
||||
enabledExtensionIds,
|
||||
|
||||
// 方法
|
||||
loadExtensions,
|
||||
getExtensionConfig
|
||||
getExtensionConfig,
|
||||
}
|
||||
})
|
@@ -1,18 +1,37 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {computed, ref} from 'vue'
|
||||
import {KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models'
|
||||
import {ExtensionID, KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models'
|
||||
import {GetAllKeyBindings} from '@/../bindings/voidraft/internal/services/keybindingservice'
|
||||
|
||||
export const useKeybindingStore = defineStore('keybinding', () => {
|
||||
// 快捷键配置数据
|
||||
const keyBindings = ref<KeyBinding[]>([])
|
||||
|
||||
|
||||
// 获取启用的快捷键
|
||||
const enabledKeyBindings = computed(() =>
|
||||
keyBindings.value.filter(kb => kb.enabled)
|
||||
)
|
||||
|
||||
// 按扩展分组的快捷键
|
||||
const keyBindingsByExtension = computed(() => {
|
||||
const groups = new Map<ExtensionID, KeyBinding[]>()
|
||||
|
||||
for (const binding of keyBindings.value) {
|
||||
if (!groups.has(binding.extension)) {
|
||||
groups.set(binding.extension, [])
|
||||
}
|
||||
groups.get(binding.extension)!.push(binding)
|
||||
}
|
||||
|
||||
return groups
|
||||
})
|
||||
|
||||
// 获取指定扩展的快捷键
|
||||
const getKeyBindingsByExtension = computed(() =>
|
||||
(extension: ExtensionID) =>
|
||||
keyBindings.value.filter(kb => kb.extension === extension)
|
||||
)
|
||||
|
||||
// 按命令获取快捷键
|
||||
const getKeyBindingByCommand = computed(() =>
|
||||
(command: KeyBindingCommand) =>
|
||||
@@ -26,7 +45,7 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
||||
try {
|
||||
keyBindings.value = await GetAllKeyBindings()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,16 +56,31 @@ export const useKeybindingStore = defineStore('keybinding', () => {
|
||||
return keyBindings.value.some(kb => kb.command === command && kb.enabled)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取扩展相关的所有扩展ID
|
||||
*/
|
||||
const getAllExtensionIds = computed(() => {
|
||||
const extensionIds = new Set<ExtensionID>()
|
||||
for (const binding of keyBindings.value) {
|
||||
extensionIds.add(binding.extension)
|
||||
}
|
||||
return Array.from(extensionIds)
|
||||
})
|
||||
|
||||
return {
|
||||
// 状态
|
||||
keyBindings,
|
||||
enabledKeyBindings,
|
||||
keyBindingsByExtension,
|
||||
getAllExtensionIds,
|
||||
|
||||
// 计算属性
|
||||
getKeyBindingByCommand,
|
||||
getKeyBindingsByExtension,
|
||||
|
||||
// 方法
|
||||
loadKeyBindings,
|
||||
hasCommand
|
||||
hasCommand,
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user