Vanessa 2024-11-21 01:11:27 +08:00
parent c0b68b1e5e
commit df3bafdb48
5 changed files with 101 additions and 95 deletions

View file

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

View file

@ -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",

View file

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

View file

@ -13,19 +13,9 @@ 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.copyHPath.custom, event)) {
fetchPost("/api/filetree/getHPathByID", {
id: protyle.block.rootID
}, (response) => {
writeText(response.data);
});
event.preventDefault();
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {
net2LocalAssets(protyle, "Img");
event.preventDefault();
@ -48,12 +38,71 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
fetchPost("/api/filetree/getHPathByID", {
id: protyle.block.rootID
}, (response) => {
writeText(response.data);
});
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 (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.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.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.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;

View file

@ -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 === "") {