From ea00753f380f1045ff357447b0e7acc9dd117a28 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 10 Oct 2023 21:18:17 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9392 --- app/src/constants.ts | 1 + app/src/menus/commonMenuItem.ts | 1 + app/src/protyle/wysiwyg/commonHotkey.ts | 11 ++++++++++- app/src/protyle/wysiwyg/keydown.ts | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/constants.ts b/app/src/constants.ts index 896b9f319..3c4a7a4d2 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -264,6 +264,7 @@ export abstract class Constants { expandUp: {default: "⌥⇧↑", custom: "⌥⇧↑"}, copyPlainText: {default: "", custom: ""}, copyID: {default: "", custom: ""}, + copyProtocolInMd: {default: "", custom: ""}, netImg2LocalAsset: {default: "", custom: ""}, optimizeTypography: {default: "", custom: ""}, hLayout: {default: "", custom: ""}, diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index e7ec9dd46..1acb67644 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -394,6 +394,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme } }, { label: window.siyuan.languages.copyProtocolInMd, + accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined, click: () => { fetchPost("/api/block/getRefText", {id}, (response) => { writeText(`[${response.data}](siyuan://blocks/${id})`); diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts index 180e34484..aa613d1cf 100644 --- a/app/src/protyle/wysiwyg/commonHotkey.ts +++ b/app/src/protyle/wysiwyg/commonHotkey.ts @@ -21,7 +21,7 @@ import {onGet} from "../util/onGet"; import {Constants} from "../../constants"; import * as dayjs from "dayjs"; -export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => { +export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => { const target = event.target as HTMLElement; if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) { fetchPost("/api/filetree/getHPathByID", { @@ -56,6 +56,15 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => { event.preventDefault(); return true; } + if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom, event)) { + const id = nodeElement ? nodeElement.getAttribute("data-node-id") : protyle.block.rootID; + fetchPost("/api/block/getRefText", {id}, (response) => { + writeText(`[${response.data}](siyuan://blocks/${id})`); + }); + event.preventDefault(); + event.stopPropagation(); + return true; + } /// #if !MOBILE if (protyle.model) { if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 34b3d1a18..ba5cbe92a 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -983,7 +983,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { return true; } /// #if !MOBILE - if (commonHotkey(protyle, event)) { + if (commonHotkey(protyle, event, nodeElement)) { return true; } /// #endif