This commit is contained in:
Vanessa 2023-11-14 23:17:58 +08:00
parent e25c9070e2
commit 6a4ed3c92b
2 changed files with 40 additions and 31 deletions

View file

@ -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();

View file

@ -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();