From 7c1f7a8280b9898bfbd5eb116fd31a0265ba082f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 2 Nov 2024 15:16:53 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12862 --- app/src/boot/globalEvent/command/protyle.ts | 13 ++++++++- app/src/protyle/gutter/index.ts | 29 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/src/boot/globalEvent/command/protyle.ts b/app/src/boot/globalEvent/command/protyle.ts index daa781811..b38142c33 100644 --- a/app/src/boot/globalEvent/command/protyle.ts +++ b/app/src/boot/globalEvent/command/protyle.ts @@ -1,6 +1,8 @@ import {hasClosestBlock} from "../../../protyle/util/hasClosest"; import {getTopAloneElement} from "../../../protyle/wysiwyg/getBlock"; import {enterBack, zoomOut} from "../../../menus/protyle"; +import {openFileById} from "../../../editor/util"; +import {Constants} from "../../../constants"; export const onlyProtyleCommand = (options: { command: string, @@ -17,7 +19,16 @@ export const onlyProtyleCommand = (options: { topNodeElement.nextElementSibling?.classList.contains("list") && topNodeElement.previousElementSibling.classList.contains("protyle-action")) { topNodeElement = topNodeElement.parentElement; } - zoomOut({protyle: options.protyle, id: topNodeElement.getAttribute("data-node-id")}); + const id = topNodeElement.getAttribute("data-node-id") + if (options.protyle.options.backlinkData) { + openFileById({ + app: options.protyle.app, + id, + action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] + }); + } else { + zoomOut({protyle: options.protyle, id}); + } return true; } if (options.command === "enterBack") { diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 269c59fed..52fade93d 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -60,6 +60,7 @@ import {avContextmenu, duplicateCompletely} from "../render/av/action"; import {getPlainText} from "../util/paste"; import {addEditorToDatabase} from "../render/av/addToDatabase"; import {processClonePHElement} from "../render/util"; +import {openFileById} from "../../editor/util"; export class Gutter { public element: HTMLElement; @@ -67,13 +68,16 @@ export class Gutter { constructor(protyle: IProtyle) { if (isMac()) { - this.gutterTip = window.siyuan.languages.gutterTip; + this.gutterTip = window.siyuan.languages.gutterTip.replace("⌥→", updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)); } else { this.gutterTip = window.siyuan.languages.gutterTip.replace("⌥→", updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)) .replace("⌘↑", updateHotkeyTip(window.siyuan.config.keymap.editor.general.collapse.custom)) .replace("⌥⌘A", updateHotkeyTip(window.siyuan.config.keymap.editor.general.attr.custom)) .replace(/⌘/g, "Ctrl+").replace(/⌥/g, "Alt+").replace(/⇧/g, "Shift+").replace(/⌃/g, "Ctrl+"); } + if (protyle.options.backlinkData) { + this.gutterTip = this.gutterTip.replace(window.siyuan.languages.enter, window.siyuan.languages.openBy) + } this.element = document.createElement("div"); this.element.className = "protyle-gutters"; this.element.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => { @@ -305,7 +309,15 @@ export class Gutter { return; } if (isOnlyMeta(event)) { - zoomOut({protyle, id}); + if (protyle.options.backlinkData) { + openFileById({ + app: protyle.app, + id, + action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] + }); + } else { + zoomOut({protyle, id}); + } } else if (event.altKey) { let foldElement: Element; Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { @@ -1695,6 +1707,19 @@ export class Gutter { enterBack(protyle, id); } }).element); + } else { + window.siyuan.menus.menu.append(new MenuItem({ + id: "enter", + accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘" + window.siyuan.languages.click)}`, + label: window.siyuan.languages.openBy, + click: () => { + openFileById({ + app: protyle.app, + id, + action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] + }); + } + }).element); } if (!protyle.disabled) { window.siyuan.menus.menu.append(new MenuItem({