Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/11561

Vanessadf3bafdb48ab
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 1513be8644..55e2594548 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -492,37 +492,27 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
event.stopPropagation();
if (hasClosestByClassName(range.startContainer, "protyle-title")) {
- fetchPost("/api/block/getRefText", {id: protyle.block.rootID}, (response) => {
- writeText(`((${protyle.block.rootID} '${response.data}'))`);
- });
+ copyTextByType([protyle.block.rootID], "ref");
} else {
const nodeElement = hasClosestBlock(range.startContainer);
if (!nodeElement) {
return false;
}
- const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
- let actionElement;
- if (selectElements.length === 1) {
- actionElement = selectElements[0];
- } else {
- const selectImgElement = nodeElement.querySelector(".img--select");
- if (selectImgElement) {
- copyPNGByLink(selectImgElement.querySelector("img").getAttribute("src"));
- return true;
- }
- actionElement = nodeElement;
+ const selectImgElement = nodeElement.querySelector(".img--select");
+ if (selectImgElement) {
+ copyPNGByLink(selectImgElement.querySelector("img").getAttribute("src"));
+ return true;
}
- const actionElementId = actionElement.getAttribute("data-node-id");
if (range.toString() !== "") {
getContentByInlineHTML(range, (content) => {
- writeText(`((${actionElementId} "${content.trim()}"))`);
+ writeText(`((${nodeElement.getAttribute("data-node-id")} "${content.trim()}"))`);
});
} else {
- fetchPost("/api/block/getRefText", {id: actionElementId}, (response) => {
- writeText(`((${actionElementId} '${response.data}'))`);
- });
+ const ids = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")).map(item => item.getAttribute("data-node-id"));
+ copyTextByType(ids, "ref");
}
}
+ return true;
}
if (hasClosestByClassName(target, "protyle-title__input")) {
return false;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 6c196001ac..592ce3ba32 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -64,6 +64,7 @@ import {processClonePHElement} from "../render/util";
import {openFileById} from "../../editor/util";
/// #endif
import {checkFold} from "../../util/noRelyPCFunction";
+import {copyTextByType} from "../toolbar/util";
export class Gutter {
public element: HTMLElement;
@@ -745,20 +746,7 @@ export class Gutter {
}
}).element);
}
- const copyMenu: IMenu[] = [{
- id: "copy",
- iconHTML: "",
- label: window.siyuan.languages.copy,
- accelerator: "⌘C",
- click() {
- if (isNotEditBlock(selectsElement[0])) {
- focusBlock(selectsElement[0]);
- } else {
- focusByRange(getEditorRange(selectsElement[0]));
- }
- document.execCommand("copy");
- }
- }, {
+ const copyMenu: IMenu[] = (copySubMenu(Array.from(selectsElement).map(item => item.getAttribute("data-node-id")), true, selectsElement[0]) as IMenu[]).concat([{
id: "copyPlainText",
iconHTML: "",
label: window.siyuan.languages.copyPlainText,
@@ -771,6 +759,19 @@ export class Gutter {
copyPlainText(html.trimEnd());
focusBlock(selectsElement[0]);
}
+ }, {
+ id: "copy",
+ iconHTML: "",
+ label: window.siyuan.languages.copy,
+ accelerator: "⌘C",
+ click() {
+ if (isNotEditBlock(selectsElement[0])) {
+ focusBlock(selectsElement[0]);
+ } else {
+ focusByRange(getEditorRange(selectsElement[0]));
+ }
+ document.execCommand("copy");
+ }
}, {
id: "duplicate",
iconHTML: "",
@@ -780,10 +781,20 @@ export class Gutter {
click() {
duplicateBlock(selectsElement, protyle);
}
- }];
+ }]);
+ copyMenu.splice(4, 1, {
+ id: "copyHPath",
+ iconHTML: "",
+ label: window.siyuan.languages.copyHPath,
+ accelerator: window.siyuan.config.keymap.editor.general.copyHPath.custom,
+ click: () => {
+ copyTextByType([selectsElement[0].getAttribute("data-node-id")], "hPath");
+ focusBlock(selectsElement[0]);
+ }
+ });
const copyTextRefMenu = this.genCopyTextRef(selectsElement);
if (copyTextRefMenu) {
- copyMenu.splice(2, 0, copyTextRefMenu);
+ copyMenu.splice(7, 0, copyTextRefMenu);
}
window.siyuan.menus.menu.append(new MenuItem({
id: "copy",
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index dc8d1c2078..f3e87f089d 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -149,18 +149,6 @@ export class Title {
getEditorRange(this.editElement).selectNodeContents(this.editElement);
event.preventDefault();
event.stopPropagation();
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) {
- writeText(protyle.block.rootID);
- event.preventDefault();
- event.stopPropagation();
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {
- writeText(`{{select * from blocks where id='${protyle.block.rootID}'}}`);
- event.preventDefault();
- event.stopPropagation();
- } else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocol.custom, event)) {
- writeText(`siyuan://blocks/${protyle.block.rootID}`);
- event.preventDefault();
- event.stopPropagation();
}
});
const iconElement = this.element.querySelector(".protyle-title__icon");
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index cd8ce71be7..ddab31abd2 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -13,8 +13,31 @@ import {Constants} from "../../constants";
import * as dayjs from "dayjs";
import {net2LocalAssets} from "../breadcrumb/action";
import {processClonePHElement} from "../render/util";
+import {copyTextByType} from "../toolbar/util";
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => {
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {
+ net2LocalAssets(protyle, "Img");
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.netAssets2LocalAssets.custom, event)) {
+ net2LocalAssets(protyle, "Assets");
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.optimizeTypography.custom, event)) {
+ fetchPost("/api/format/autoSpace", {
+ id: protyle.block.rootID
+ });
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
fetchPost("/api/filetree/getHPathByID", {
id: protyle.block.rootID
@@ -26,34 +49,60 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {
- net2LocalAssets(protyle, "Img");
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom, event)) {
+ if (nodeElement) {
+ const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+ if (selectElements.length > 0) {
+ selectElements.push(nodeElement);
+ }
+ copyTextByType(selectElements.map(item => item.getAttribute("data-node-id")), "protocolMd")
+ } else {
+ copyTextByType([protyle.block.rootID], "protocolMd")
+ }
event.preventDefault();
event.stopPropagation();
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.netAssets2LocalAssets.custom, event)) {
- net2LocalAssets(protyle, "Assets");
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) {
+ if (nodeElement) {
+ const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+ if (selectElements.length > 0) {
+ selectElements.push(nodeElement);
+ }
+ copyTextByType(selectElements.map(item => item.getAttribute("data-node-id")), "id")
+ } else {
+ copyTextByType([protyle.block.rootID], "id")
+ }
event.preventDefault();
event.stopPropagation();
return true;
}
-
- if (matchHotKey(window.siyuan.config.keymap.editor.general.optimizeTypography.custom, event)) {
- fetchPost("/api/format/autoSpace", {
- id: protyle.block.rootID
- });
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocol.custom, event)) {
+ if (nodeElement) {
+ const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+ if (selectElements.length > 0) {
+ selectElements.push(nodeElement);
+ }
+ copyTextByType(selectElements.map(item => item.getAttribute("data-node-id")), "protocol")
+ } else {
+ copyTextByType([protyle.block.rootID], "protocol")
+ }
event.preventDefault();
event.stopPropagation();
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})`);
- });
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {
+ if (nodeElement) {
+ const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+ if (selectElements.length > 0) {
+ selectElements.push(nodeElement);
+ }
+ copyTextByType(selectElements.map(item => item.getAttribute("data-node-id")), "blockEmbed")
+ } else {
+ copyTextByType([protyle.block.rootID], "blockEmbed")
+ }
event.preventDefault();
event.stopPropagation();
return true;
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index db980eea6b..b6ccabffed 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -969,30 +969,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.copyProtocol.custom, event)) {
- const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
- let actionElement;
- if (selectElements.length === 1) {
- actionElement = selectElements[0];
- } else {
- actionElement = nodeElement;
- }
- writeText(`siyuan://blocks/${actionElement.getAttribute("data-node-id")}`);
- event.preventDefault();
- event.stopPropagation();
- return true;
- }
/// #if !MOBILE
if (commonHotkey(protyle, event, nodeElement)) {
return true;
}
/// #endif
- if (matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) {
- writeText(nodeElement.getAttribute("data-node-id"));
- event.preventDefault();
- event.stopPropagation();
- return true;
- }
+
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyText.custom, event)) {
// 用于标识复制文本 *
if (selectText !== "") {
@@ -1014,20 +996,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.stopPropagation();
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {
- const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
- let actionElement;
- if (selectElements.length === 1) {
- actionElement = selectElements[0];
- } else {
- actionElement = nodeElement;
- }
- writeText(`{{select * from blocks where id='${actionElement.getAttribute("data-node-id")}'}}`);
- event.preventDefault();
- event.stopPropagation();
- return true;
- }
-
if (matchHotKey(window.siyuan.config.keymap.editor.general.attr.custom, event)) {
const topElement = getTopAloneElement(nodeElement);
if (selectText === "") {