46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import { Extension } from '@codemirror/state';
|
|
import { useKeybindingStore } from '@/stores/keybindingStore';
|
|
import { useExtensionStore } from '@/stores/extensionStore';
|
|
import { Manager } from './manager';
|
|
|
|
/**
|
|
* 异步创建快捷键扩展
|
|
*/
|
|
export const createDynamicKeymapExtension = async (): Promise<Extension> => {
|
|
const keybindingStore = useKeybindingStore();
|
|
const extensionStore = useExtensionStore();
|
|
|
|
// 确保快捷键配置已加载
|
|
if (keybindingStore.keyBindings.length === 0) {
|
|
await keybindingStore.loadKeyBindings();
|
|
}
|
|
|
|
// 确保扩展配置已加载
|
|
if (extensionStore.extensions.length === 0) {
|
|
await extensionStore.loadExtensions();
|
|
}
|
|
|
|
// 获取启用的扩展ID列表
|
|
const enabledExtensionIds = extensionStore.enabledExtensions.map(ext => ext.id);
|
|
|
|
return Manager.createKeymapExtension(keybindingStore.keyBindings, enabledExtensionIds);
|
|
};
|
|
|
|
/**
|
|
* 更新快捷键映射
|
|
* @param view 编辑器视图
|
|
*/
|
|
export const updateKeymapExtension = (view: any): void => {
|
|
const keybindingStore = useKeybindingStore();
|
|
const extensionStore = useExtensionStore();
|
|
|
|
// 获取启用的扩展ID列表
|
|
const enabledExtensionIds = extensionStore.enabledExtensions.map(ext => ext.id);
|
|
|
|
Manager.updateKeymap(view, keybindingStore.keyBindings, enabledExtensionIds);
|
|
};
|
|
|
|
// 导出相关模块
|
|
export { Manager } from './manager';
|
|
export { commands, getCommandHandler, getCommandDescription, isCommandRegistered, getRegisteredCommands } from './commands';
|
|
export type { KeyBinding, CommandHandler, CommandDefinition, KeymapResult } from './types'; |