mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-06 12:50:16 +01:00
This commit is contained in:
parent
e25c9070e2
commit
6a4ed3c92b
2 changed files with 40 additions and 31 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue