Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/5145

Vanessadd19b9bc448b
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index ae29c386af..c28819bb9b 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -25,6 +25,7 @@ import {openBacklink, openGraph, openOutline, updatePanelByEditor} from "../../e
import * as dayjs from "dayjs";
import {setTitle} from "../../dialog/processSystem";
import {getNoContainerElement} from "../wysiwyg/getBlock";
+import {commonHotkey} from "../wysiwyg/commonHotkey";
export class Title {
public element: HTMLElement;
@@ -82,6 +83,11 @@ export class Title {
if (event.isComposing) {
return;
}
+
+ if (commonHotkey(protyle, event)) {
+ return true;
+ }
+
if (event.key === "ArrowDown" || event.key === "Enter") {
const noContainerElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild);
// https://github.com/siyuan-note/siyuan/issues/4923
@@ -114,32 +120,6 @@ export class Title {
writeText(`siyuan://blocks/${protyle.block.rootID}`);
event.preventDefault();
event.stopPropagation();
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
- fetchPost("/api/filetree/getHPathByID", {
- id: protyle.block.rootID
- }, (response) => {
- writeText(response.data);
- });
- event.preventDefault();
- event.stopPropagation();
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
- event.preventDefault();
- event.stopPropagation();
- openBacklink(protyle);
- return;
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
- event.preventDefault();
- event.stopPropagation();
- openGraph(protyle);
- return;
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
- event.preventDefault();
- event.stopPropagation();
- const offset = getSelectionOffset(this.editElement);
- openOutline(protyle);
- // switchWnd 后,range会被清空,需要重新设置
- focusByOffset(this.editElement, offset.start, offset.end);
- return;
}
});
const iconElement = this.element.querySelector(".protyle-title__icon");
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
new file mode 100644
index 0000000000..300750a5bd
--- /dev/null
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -0,0 +1,68 @@
+import {matchHotKey} from "../util/hotKey";
+import {fetchPost} from "../../util/fetch";
+import {writeText} from "../util/compatibility";
+import {openBacklink, openGraph, openOutline} from "../../editor/util";
+import {focusByOffset, getSelectionOffset} from "../util/selection";
+import {fullscreen} from "../breadcrumb/action";
+import {addLoading, setPadding} from "../ui/initUI";
+import {Constants} from "../../constants";
+import {onGet} from "../util/onGet";
+
+export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
+ const target = event.target as HTMLElement
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
+ fetchPost("/api/filetree/getHPathByID", {
+ id: protyle.block.rootID
+ }, (response) => {
+ writeText(response.data);
+ });
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
+ protyle.title.render(protyle, true);
+ addLoading(protyle);
+ fetchPost("/api/filetree/getDoc", {
+ id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
+ mode: 0,
+ size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
+ }, getResponse => {
+ onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);
+ });
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.fullscreen.custom, event)) {
+ fullscreen(protyle.element);
+ setPadding(protyle);
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+ if (protyle.model) {
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
+ event.preventDefault();
+ event.stopPropagation();
+ openBacklink(protyle);
+ return true;
+ }
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
+ event.preventDefault();
+ event.stopPropagation();
+ openGraph(protyle);
+ 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;
+ }
+ }
+}
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 9076a50276..7dd8852c4e 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -45,10 +45,11 @@ import {bindMenuKeydown} from "../../menus/Menu";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {scrollCenter} from "../../util/highlightById";
-import {openBacklink, openBy, openFileById, openGraph, openOutline} from "../../editor/util";
+import {openBy, openFileById} from "../../editor/util";
import {BlockPanel} from "../../block/Panel";
import * as dayjs from "dayjs";
import {highlightRender} from "../markdown/highlightRender";
+import {commonHotkey} from "./commonHotkey";
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
@@ -449,19 +450,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.stopPropagation();
return;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
- protyle.title.render(protyle, true);
- addLoading(protyle);
- fetchPost("/api/filetree/getDoc", {
- id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
- mode: 0,
- size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
- }, getResponse => {
- onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);
- });
- event.preventDefault();
- return;
- }
if (matchHotKey("⌘/", event)) {
event.stopPropagation();
event.preventDefault();
@@ -724,13 +712,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.fullscreen.custom, event)) {
- fullscreen(protyle.element);
- setPadding(protyle);
- event.preventDefault();
- return true;
- }
-
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
protyle.undo.undo(protyle);
event.preventDefault();
@@ -758,13 +739,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
- fetchPost("/api/filetree/getHPathByID", {
- id: protyle.block.rootID
- }, (response) => {
- writeText(response.data);
- });
- event.preventDefault();
+ if (commonHotkey(protyle, event)) {
return true;
}
@@ -1397,26 +1372,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
}
- if (protyle.model) {
- if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
- event.preventDefault();
- openOutline(protyle);
- return;
- }
-
- if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
- event.preventDefault();
- openBacklink(protyle);
- return;
- }
-
- if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
- event.preventDefault();
- openGraph(protyle);
- return;
- }
- }
-
/// #if !BROWSER
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
writeText(clipboard.readText());