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/9653

Vanessa6a4ed3c92b54
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 3f865c194d..cd67a4dcee 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -1,4 +1,11 @@
-import {isMac, isNotCtrl, isOnlyMeta, updateHotkeyTip, writeText} from "../../protyle/util/compatibility";
+import {
+ copyPlainText,
+ isMac,
+ isNotCtrl,
+ isOnlyMeta,
+ updateHotkeyTip,
+ writeText
+} from "../../protyle/util/compatibility";
import {matchHotKey} from "../../protyle/util/hotKey";
import {openSearch} from "../../search/spread";
import {
@@ -312,6 +319,38 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
if (target.tagName !== "TABLE" && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) {
return false;
}
+ if (matchHotKey(window.siyuan.config.keymap.editor.general.copyPlainText.custom, event)) {
+ const nodeElement = hasClosestBlock(range.startContainer);
+ if (!nodeElement) {
+ return false;
+ }
+ if (range.toString() === "") {
+ const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+ let html = "";
+ if (selectsElement.length === 0) {
+ selectsElement.push(nodeElement);
+ }
+ selectsElement.forEach(item => {
+ // 不能使用 [contenteditable="true"], 否则嵌入块无法复制
+ item.querySelectorAll("[spellcheck]").forEach(editItem => {
+ const cloneNode = editItem.cloneNode(true) as HTMLElement;
+ cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
+ slashItem.firstElementChild.remove();
+ });
+ html += cloneNode.textContent + "\n";
+ });
+ });
+ copyPlainText(html.trimEnd());
+ } else {
+ const cloneContents = range.cloneContents();
+ cloneContents.querySelectorAll('[data-type="backslash"]').forEach(item => {
+ item.firstElementChild.remove();
+ });
+ writeText(cloneContents.textContent);
+ }
+ event.preventDefault();
+ return true;
+ }
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
reloadProtyle(protyle, true);
event.preventDefault();
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index e71b1cbc9a..f6aa408a42 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -1463,36 +1463,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
// 复制块不能单纯的 BlockDOM2StdMd,否则 https://github.com/siyuan-note/siyuan/issues/9362
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.copyPlainText.custom, event)) {
- if (selectText === "") {
- const selectsElement: HTMLElement[] = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
- let html = "";
- if (selectsElement.length === 0) {
- selectsElement.push(nodeElement);
- }
- selectsElement.forEach(item => {
- // 不能使用 [contenteditable="true"], 否则嵌入块无法复制
- item.querySelectorAll("[spellcheck]").forEach(editItem => {
- const cloneNode = editItem.cloneNode(true) as HTMLElement;
- cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
- slashItem.firstElementChild.remove();
- });
- html += cloneNode.textContent + "\n";
- });
- });
- copyPlainText(html.trimEnd());
- } else {
- const cloneContents = range.cloneContents();
- cloneContents.querySelectorAll('[data-type="backslash"]').forEach(item => {
- item.firstElementChild.remove();
- });
- writeText(cloneContents.textContent);
- }
- event.preventDefault();
- event.stopPropagation();
- return;
- }
-
if (matchHotKey(window.siyuan.config.keymap.editor.general.vLayout.custom, event)) {
event.preventDefault();
event.stopPropagation();