From 50b2cef6908d071c6d610a05d52170b2e6892abe Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 2 Nov 2023 09:29:57 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9548 --- app/src/boot/globalEvent/keydown.ts | 2 + app/src/boot/globalEvent/searchKeydown.ts | 77 ++++++++++++++++++----- app/src/menus/search.ts | 2 +- 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 8cee4904c..56e076532 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -979,6 +979,8 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => { // 仅处理以下快捷键操作 if (!event.ctrlKey && !isCtrl(event) && event.key !== "Escape" && !event.shiftKey && !event.altKey && + Constants.KEYCODELIST[event.keyCode] !== "PageUp" && + Constants.KEYCODELIST[event.keyCode] !== "PageDown" && !/^F\d{1,2}$/.test(event.key) && event.key.indexOf("Arrow") === -1 && event.key !== "Enter" && event.key !== "Backspace" && event.key !== "Delete") { return; } diff --git a/app/src/boot/globalEvent/searchKeydown.ts b/app/src/boot/globalEvent/searchKeydown.ts index 04f131a7f..ab08d8c91 100644 --- a/app/src/boot/globalEvent/searchKeydown.ts +++ b/app/src/boot/globalEvent/searchKeydown.ts @@ -14,6 +14,8 @@ import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {getArticle, inputEvent, replace, toggleReplaceHistory, toggleSearchHistory} from "../../search/util"; import {showFileInFolder} from "../../util/pathName"; import {assetInputEvent, renderPreview, toggleAssetHistory} from "../../search/assets"; +import {initSearchMenu} from "../../menus/search"; +import {writeText} from "../../protyle/util/compatibility"; export const searchKeydown = (app: App, event: KeyboardEvent) => { if (getSelection().rangeCount === 0) { @@ -135,24 +137,67 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => { } return false; } - if (!isAsset && matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) { - const id = currentList.getAttribute("data-node-id"); - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { - openFileById({ - app, - id, - position: "right", - action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : - (id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]), - zoomIn: foldResponse.data + if (!isAsset) { + if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) { + const id = currentList.getAttribute("data-node-id"); + fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + openFileById({ + app, + id, + position: "right", + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : + (id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]), + zoomIn: foldResponse.data + }); + if (dialog) { + dialog.destroy({focus: "false"}); + } }); - if (dialog) { - dialog.destroy({focus: "false"}); - } - }); - return true; + return true; + } + const id = currentList.getAttribute("data-node-id") + if (matchHotKey("⌘/", event)) { + const currentRect = currentList.getBoundingClientRect(); + initSearchMenu(id).popup({ + x: currentRect.left + 30, + y: currentRect.bottom + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) { + fetchPost("/api/block/getRefText", {id}, (response) => { + writeText(`((${id} '${response.data}'))`); + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) { + writeText(`{{select * from blocks where id='${id}'}}`); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocol.custom, event)) { + writeText(`siyuan://blocks/${id}`); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom, event)) { + fetchPost("/api/block/getRefText", {id}, (response) => { + writeText(`[${response.data}](siyuan://blocks/${id})`); + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) { + fetchPost("/api/filetree/getHPathByID", { + id + }, (response) => { + writeText(response.data); + }); + return true; + } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) { + writeText(id); + return true; + } } - // TODO https://github.com/siyuan-note/siyuan/issues/9548 + if (Constants.KEYCODELIST[event.keyCode] === "PageUp") { if (isAsset) { if (!assetsElement.querySelector('[data-type="assetPrevious"]').getAttribute("disabled")) { diff --git a/app/src/menus/search.ts b/app/src/menus/search.ts index 1cb6bd7fa..1f0eab4b5 100644 --- a/app/src/menus/search.ts +++ b/app/src/menus/search.ts @@ -6,7 +6,7 @@ export const initSearchMenu = (id: string) => { window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.copy, type: "submenu", - submenu: copySubMenu(id,false) + submenu: copySubMenu(id) }).element); return window.siyuan.menus.menu; };