This commit is contained in:
Vanessa 2023-10-22 17:49:51 +08:00
parent 5d49168659
commit e34d1a1401
3 changed files with 40 additions and 35 deletions

View file

@ -1,4 +1,4 @@
import {isCtrl, isMac, updateHotkeyTip} from "../../protyle/util/compatibility";
import {isCtrl, isMac, updateHotkeyTip, writeText} from "../../protyle/util/compatibility";
import {matchHotKey} from "../../protyle/util/hotKey";
import {openSearch} from "../../search/spread";
import {
@ -60,6 +60,8 @@ import {Custom} from "../../layout/dock/Custom";
import {Protyle} from "../../protyle";
import {transaction} from "../../protyle/wysiwyg/transaction";
import {quickMakeCard} from "../../card/makeCard";
import {copyPNG} from "../../menus/util";
import {getContentByInlineHTML} from "../../protyle/wysiwyg/keydown";
const switchDialogEvent = (app: App, event: MouseEvent) => {
event.preventDefault();
@ -336,6 +338,42 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
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}'))`);
});
} 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) {
copyPNG(selectImgElement.querySelector("img"));
return true;
}
actionElement = nodeElement;
}
const actionElementId = actionElement.getAttribute("data-node-id");
if (range.toString() !== "") {
getContentByInlineHTML(range, (content) => {
writeText(`((${actionElementId} "${Lute.EscapeHTMLStr(content.trim())}"))`);
});
} else {
fetchPost("/api/block/getRefText", {id: actionElementId}, (response) => {
writeText(`((${actionElementId} '${response.data}'))`);
});
}
}
}
if (hasClosestByClassName(target, "protyle-title__input")) {
return false;
}

View file

@ -134,12 +134,6 @@ export class Title {
getEditorRange(this.editElement).selectNodeContents(this.editElement);
event.preventDefault();
event.stopPropagation();
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
fetchPost("/api/block/getRefText", {id: protyle.block.rootID}, (response) => {
writeText(`((${protyle.block.rootID} '${response.data}'))`);
});
event.preventDefault();
event.stopPropagation();
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.copyID.custom, event)) {
writeText(protyle.block.rootID);
event.preventDefault();

View file

@ -73,7 +73,7 @@ import {avKeydown} from "../render/av/keydown";
import {resizeAV} from "../util/resize";
const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {
export const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {
let html = "";
Array.from(range.cloneContents().childNodes).forEach((item: HTMLElement) => {
if (item.nodeType === 3) {
@ -1009,33 +1009,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) {
event.preventDefault();
event.stopPropagation();
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) {
copyPNG(selectImgElement.querySelector("img"));
return true;
}
actionElement = nodeElement;
}
const actionElementId = actionElement.getAttribute("data-node-id");
if (selectText !== "") {
getContentByInlineHTML(range, (content) => {
writeText(`((${actionElementId} "${Lute.EscapeHTMLStr(content.trim())}"))`);
});
} else {
fetchPost("/api/block/getRefText", {id: actionElementId}, (response) => {
writeText(`((${actionElementId} '${response.data}'))`);
});
}
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
let actionElement;