fix(脑图): 新增节点操作监听快捷键编辑事件修复

This commit is contained in:
baiqi 2024-11-12 18:10:42 +08:00 committed by Craftsman
parent 344a933278
commit 3eaeb27630
2 changed files with 24 additions and 1 deletions

View File

@ -229,6 +229,7 @@
count: props.modulesCount[e.id], count: props.modulesCount[e.id],
isNew: false, isNew: false,
changed: false, changed: false,
disabled: ['NONE', 'root'].includes(e.id || e.data?.id), //
}, },
children: children:
props.modulesCount[e.id] > 0 && !e.children?.length props.modulesCount[e.id] > 0 && !e.children?.length

View File

@ -59,7 +59,6 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
'enter': 'appendSiblingNode', 'enter': 'appendSiblingNode',
'tab': 'appendChildNode', 'tab': 'appendChildNode',
'backspace': 'delete', 'backspace': 'delete',
'f2': 'input', // 进入编辑状态
}; };
// 业务快捷键 // 业务快捷键
const businessShortcuts: { [key: string]: ShortcutKey } = { const businessShortcuts: { [key: string]: ShortcutKey } = {
@ -98,6 +97,27 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
} }
}; };
const handleShortcutInput = (event: KeyboardEvent) => {
const { editor } = window;
const { fsm } = editor;
const state = fsm.state();
switch (state) {
case 'input': {
// 输入状态下不响应快捷键
return;
}
default:
}
const key = event.key.toLowerCase();
if (key === 'f2') {
// 执行快捷键编辑事件
if (shortcuts.input) {
shortcuts.input(event);
}
}
};
const handleShortcutSave = (event: KeyboardEvent) => { const handleShortcutSave = (event: KeyboardEvent) => {
const { editor } = window; const { editor } = window;
const { fsm } = editor; const { fsm } = editor;
@ -124,6 +144,7 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
const minderContainer = document.querySelector('.ms-minder-container'); const minderContainer = document.querySelector('.ms-minder-container');
if (minderContainer) { if (minderContainer) {
window.addEventListener('keydown', handleShortcutSave); window.addEventListener('keydown', handleShortcutSave);
window.addEventListener('keydown', handleShortcutInput);
minderContainer.addEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent)); minderContainer.addEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent));
minderContainer.addEventListener('copy', (e) => minderCopy(e as ClipboardEvent)); minderContainer.addEventListener('copy', (e) => minderCopy(e as ClipboardEvent));
minderContainer.addEventListener('cut', (e) => minderCut(e as ClipboardEvent)); minderContainer.addEventListener('cut', (e) => minderCut(e as ClipboardEvent));
@ -135,6 +156,7 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
const minderContainer = document.querySelector('.ms-minder-container'); const minderContainer = document.querySelector('.ms-minder-container');
if (minderContainer) { if (minderContainer) {
window.removeEventListener('keydown', handleShortcutSave); window.removeEventListener('keydown', handleShortcutSave);
window.removeEventListener('keydown', handleShortcutInput);
minderContainer.removeEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent)); minderContainer.removeEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent));
minderContainer.removeEventListener('copy', (e) => minderCopy(e as ClipboardEvent)); minderContainer.removeEventListener('copy', (e) => minderCopy(e as ClipboardEvent));
minderContainer.removeEventListener('cut', (e) => minderCut(e as ClipboardEvent)); minderContainer.removeEventListener('cut', (e) => minderCut(e as ClipboardEvent));