From 9ac2fd017241026ba78794ec01fe8e15f4683b56 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 27 Nov 2023 09:07:41 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9745 --- app/src/boot/globalEvent/keydown.ts | 54 ++++++++++++++++++++++++- app/src/protyle/wysiwyg/commonHotkey.ts | 54 ------------------------- 2 files changed, 52 insertions(+), 56 deletions(-) diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index bdbb0715b..2200ae78d 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -34,7 +34,7 @@ import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath} fr import {openFileById} from "../../editor/util"; import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll"; import {openGlobalSearch} from "../../search/util"; -import {focusBlock, focusByRange} from "../../protyle/util/selection"; +import {focusBlock, focusByOffset, focusByRange, getSelectionOffset} from "../../protyle/util/selection"; import {initFileMenu, initNavigationMenu} from "../../menus/navigation"; import {bindMenuKeydown} from "../../menus/Menu"; import {Dialog} from "../../dialog"; @@ -61,7 +61,7 @@ import {fullscreen} from "../../protyle/breadcrumb/action"; import {openRecentDocs} from "../../business/openRecentDocs"; import {App} from "../../index"; import {commandPanel} from "../../plugin/commandPanel"; -import {toggleDockBar} from "../../layout/dock/util"; +import {openBacklink, openGraph, openOutline, toggleDockBar} from "../../layout/dock/util"; import {workspaceMenu} from "../../menus/workspace"; import {resize} from "../../protyle/util/resize"; import {Search} from "../../search"; @@ -325,6 +325,56 @@ const editKeydown = (app: App, event: KeyboardEvent) => { if (target.tagName !== "TABLE" && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) { return false; } + if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { + event.preventDefault(); + if (range) { + const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); + if (refElement) { + openBacklink({ + app: protyle.app, + blockId: refElement.dataset.id, + }); + return true; + } + } + openBacklink({ + app: protyle.app, + blockId: protyle.block.id, + rootId: protyle.block.rootID, + useBlockId: protyle.block.showAll, + title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null, + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) { + event.preventDefault(); + if (range) { + const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); + if (refElement) { + openGraph({ + app: protyle.app, + blockId: refElement.dataset.id, + }); + return true; + } + } + openGraph({ + app: protyle.app, + blockId: protyle.block.id, + rootId: protyle.block.rootID, + useBlockId: protyle.block.showAll, + title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null, + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) { + event.preventDefault(); + const offset = getSelectionOffset(target); + openOutline(protyle); + // switchWnd 后,range会被清空,需要重新设置 + focusByOffset(target, offset.start, offset.end); + return true; + } if (matchHotKey(window.siyuan.config.keymap.editor.general.copyPlainText.custom, event)) { const nodeElement = hasClosestBlock(range.startContainer); if (!nodeElement) { diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index fd01f0ae4..063207384 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -66,60 +66,6 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen return true; } /// #if !MOBILE - if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { - event.preventDefault(); - event.stopPropagation(); - if (range) { - const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); - if (refElement) { - openBacklink({ - app: protyle.app, - blockId: refElement.dataset.id, - }); - return true; - } - } - openBacklink({ - app: protyle.app, - blockId: protyle.block.id, - rootId: protyle.block.rootID, - useBlockId: protyle.block.showAll, - title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null, - }); - return true; - } - if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) { - event.preventDefault(); - event.stopPropagation(); - if (range) { - const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); - if (refElement) { - openGraph({ - app: protyle.app, - blockId: refElement.dataset.id, - }); - return true; - } - } - openGraph({ - app: protyle.app, - blockId: protyle.block.id, - rootId: protyle.block.rootID, - useBlockId: protyle.block.showAll, - title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null, - }); - return true; - } - if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) { - event.preventDefault(); - event.stopPropagation(); - const offset = getSelectionOffset(target); - openOutline(protyle); - // switchWnd 后,range会被清空,需要重新设置 - focusByOffset(target, offset.start, offset.end); - return true; - } - let matchCommand = false; protyle.app.plugins.find(item => { item.commands.find(command => {