chore(editor): 修改拼写错误

This commit is contained in:
roymondchen 2023-12-18 14:17:04 +08:00
parent 538f96c082
commit 09fe6d29e2
5 changed files with 58 additions and 23 deletions

View File

@ -155,8 +155,8 @@ const services: Services = {
initServiceEvents(props, emit, services);
initServiceState(props, services);
keybindingService.registe(keybindingConfig);
keybindingService.registeEl('global');
keybindingService.register(keybindingConfig);
keybindingService.registerEl('global');
provide('services', services);

View File

@ -6,7 +6,7 @@ import { KeyBindingContainerKey } from '@editor/utils/keybinding-config';
export const useKeybinding = (
services: Services | undefined,
contianer: Ref<InstanceType<typeof Tree> | undefined>,
container: Ref<InstanceType<typeof Tree> | undefined>,
) => {
const keybindingService = services?.keybindingService;
@ -17,17 +17,17 @@ export const useKeybinding = (
isCtrlKeyDown.value = false;
};
keybindingService?.registeCommand('layer-panel-global-keyup', () => {
keybindingService?.registerCommand('layer-panel-global-keyup', () => {
isCtrlKeyDown.value = false;
});
keybindingService?.registeCommand('layer-panel-global-keydwon', () => {
keybindingService?.registerCommand('layer-panel-global-keydown', () => {
isCtrlKeyDown.value = true;
});
keybindingService?.registe([
keybindingService?.register([
{
command: 'layer-panel-global-keydwon',
command: 'layer-panel-global-keydown',
keybinding: 'ctrl',
when: [['global', 'keydown']],
},
@ -39,12 +39,12 @@ export const useKeybinding = (
]);
watchEffect(() => {
if (contianer.value) {
if (container.value) {
globalThis.addEventListener('blur', windowBlurHandler);
keybindingService?.registeEl(KeyBindingContainerKey.LAYER_PANEL, contianer.value.$el);
keybindingService?.registerEl(KeyBindingContainerKey.LAYER_PANEL, container.value.$el);
} else {
globalThis.removeEventListener('blur', windowBlurHandler);
keybindingService?.unregisteEl(KeyBindingContainerKey.LAYER_PANEL);
keybindingService?.unregisterEl(KeyBindingContainerKey.LAYER_PANEL);
}
});

View File

@ -136,7 +136,7 @@ const resizeObserver = new ResizeObserver((entries) => {
onMounted(() => {
if (stageWrap.value?.container) {
resizeObserver.observe(stageWrap.value.container);
services?.keybindingService.registeEl(KeyBindingContainerKey.STAGE, stageWrap.value.container);
services?.keybindingService.registerEl(KeyBindingContainerKey.STAGE, stageWrap.value.container);
}
});
@ -144,7 +144,7 @@ onBeforeUnmount(() => {
stage?.destroy();
resizeObserver.disconnect();
services?.editorService.set('stage', null);
services?.keybindingService.unregisteEl('stage');
services?.keybindingService.unregisterEl('stage');
services?.editorService.off('root-change', rootChangeHandler);
});

View File

@ -84,15 +84,29 @@ class Keybinding extends BaseService {
},
};
public registeCommand(command: string, handler: (e: KeyboardEvent) => void | Promise<void>) {
public registerCommand(command: string, handler: (e: KeyboardEvent) => void | Promise<void>) {
this.commands[command] = handler;
}
public unregisteCommand(command: string) {
/**
* @deprecated
*/
public registeCommand(command: string, handler: (e: KeyboardEvent) => void | Promise<void>) {
this.registerCommand(command, handler);
}
public unregisterCommand(command: string) {
delete this.commands[command];
}
public registeEl(name: string, el?: HTMLElement) {
/**
* @deprecated
*/
public unregisteCommand(command: string) {
this.unregisterCommand(command);
}
public registerEl(name: string, el?: HTMLElement) {
if (name !== 'global' && !el) {
throw new Error('只有name为global可以不传el');
}
@ -102,20 +116,34 @@ class Keybinding extends BaseService {
this.bind(name);
}
public unregisteEl(name: string) {
/**
* @deprecated
*/
public registeEl(name: string, el?: HTMLElement) {
this.registerEl(name, el);
}
public unregisterEl(name: string) {
this.controllers.get(name)?.destroy();
this.controllers.delete(name);
this.bindingList.forEach((item) => {
item.binded = false;
item.bound = false;
});
}
public registe(maps: KeyBindingItem[]) {
/**
* @deprecated
*/
public unregisteEl(name: string) {
this.unregisterEl(name);
}
public register(maps: KeyBindingItem[]) {
for (const keybindingItem of maps) {
const { command, keybinding, when } = keybindingItem;
for (const [type = '', eventType = 'keydown'] of when) {
const cacheItem: KeyBindingCacheItem = { type, command, keybinding, eventType, binded: false };
const cacheItem: KeyBindingCacheItem = { type, command, keybinding, eventType, bound: false };
this.bindingList.push(cacheItem);
}
@ -124,6 +152,13 @@ class Keybinding extends BaseService {
this.bind();
}
/**
* @deprecated
*/
public registe(map: KeyBindingItem[]) {
this.register(map);
}
public reset() {
this.controllers.forEach((keycon) => {
keycon.destroy();
@ -138,13 +173,13 @@ class Keybinding extends BaseService {
private bind(name?: string) {
for (const item of this.bindingList) {
const { type, eventType, command, keybinding, binded } = item;
const { type, eventType, command, keybinding, bound } = item;
if (name && name !== type) {
continue;
}
if (binded) {
if (bound) {
continue;
}
@ -166,7 +201,7 @@ class Keybinding extends BaseService {
}
});
item.binded = true;
item.bound = true;
}
}

View File

@ -574,7 +574,7 @@ export interface KeyBindingCacheItem {
command: KeyBindingCommand | string;
keybinding?: string | string[];
eventType: 'keyup' | 'keydown';
binded: boolean;
bound: boolean;
}
export interface CodeSelectColConfig {