fix(脑图): 快捷键保存

--bug=1046501 --user=白奇 可以在不聚焦脑图节点的状态下,使用快捷键保存脑图 https://www.tapd.cn/55049933/s/1582304
This commit is contained in:
baiqi 2024-09-20 14:10:24 +08:00 committed by Craftsman
parent 5398e97410
commit fcc2ee8baa
1 changed files with 24 additions and 1 deletions

View File

@ -51,7 +51,6 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
// z: 'undo', // 撤销 TODO:暂时不上撤销和重做
// y: 'redo', // 重做
enter: 'enter', // 进入节点
s: 'save', // 保存
};
// 定义单键事件
const singleShortcuts: { [key: string]: ShortcutKey } = {
@ -97,9 +96,32 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
}
};
const handleShortcutSave = (event: KeyboardEvent) => {
const { editor } = window;
const { fsm } = editor;
const state = fsm.state();
switch (state) {
case 'input': {
// 输入状态下不响应快捷键
return;
}
default:
}
const key = event.key.toLowerCase();
const isCtrlOrCmd = event.ctrlKey || event.metaKey;
if (isCtrlOrCmd && key === 's') {
// 执行快捷键保存事件
if (shortcuts.save) {
shortcuts.save(event);
}
}
};
onMounted(() => {
const minderContainer = document.querySelector('.ms-minder-container');
if (minderContainer) {
window.addEventListener('keydown', handleShortcutSave);
minderContainer.addEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent));
minderContainer.addEventListener('copy', (e) => minderCopy(e as ClipboardEvent));
minderContainer.addEventListener('cut', (e) => minderCut(e as ClipboardEvent));
@ -110,6 +132,7 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
function unbindShortcuts() {
const minderContainer = document.querySelector('.ms-minder-container');
if (minderContainer) {
window.removeEventListener('keydown', handleShortcutSave);
minderContainer.removeEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent));
minderContainer.removeEventListener('copy', (e) => minderCopy(e as ClipboardEvent));
minderContainer.removeEventListener('cut', (e) => minderCut(e as ClipboardEvent));