Vanessa 2024-11-21 00:22:20 +08:00
parent 028e3118c4
commit c0b68b1e5e
5 changed files with 121 additions and 96 deletions

View file

@ -22,6 +22,7 @@ import {App} from "../index";
import {renderAVAttribute} from "../protyle/render/av/blockAttr";
import {openAssetNewWindow} from "../window/openNewWindow";
import {escapeHtml} from "../util/escape";
import {copyTextByType} from "../protyle/toolbar/util";
const bindAttrInput = (inputElement: HTMLInputElement, id: string) => {
inputElement.addEventListener("change", () => {
@ -377,21 +378,8 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
iconHTML: "",
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
label: window.siyuan.languages.copyBlockRef,
click: async () => {
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
const response = await fetchSyncPost("/api/block/getRefText", {id});
const content = `((${id} '${response.data}'))`;
if (ids.length > 1) {
text += "* ";
}
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n";
}
}
writeText(text);
click: () => {
copyTextByType(ids, "ref");
if (focusElement) {
focusBlock(focusElement);
}
@ -402,17 +390,7 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
label: window.siyuan.languages.copyBlockEmbed,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
click: () => {
let text = "";
ids.forEach((id, index) => {
if (ids.length > 1) {
text += "* ";
}
text += `{{select * from blocks where id='${id}'}}`;
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n";
}
});
writeText(text);
copyTextByType(ids, "blockEmbed");
if (focusElement) {
focusBlock(focusElement);
}
@ -423,17 +401,7 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
label: window.siyuan.languages.copyProtocol,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
click: () => {
let text = "";
ids.forEach((id, index) => {
if (ids.length > 1) {
text += "* ";
}
text += `siyuan://blocks/${id}`;
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n";
}
});
writeText(text);
copyTextByType(ids, "protocol");
if (focusElement) {
focusBlock(focusElement);
}
@ -443,21 +411,8 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
iconHTML: "",
label: window.siyuan.languages.copyProtocolInMd,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined,
click: async () => {
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
const response = await fetchSyncPost("/api/block/getRefText", {id});
const content = `[${response.data}](siyuan://blocks/${id})`;
if (ids.length > 1) {
text += "* ";
}
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n";
}
}
writeText(text);
click: () => {
copyTextByType(ids, "protocolMd");
if (focusElement) {
focusBlock(focusElement);
}
@ -467,21 +422,11 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
iconHTML: "",
label: window.siyuan.languages.copyHPath,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
click: async () => {
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
const content = response.data;
if (ids.length > 1) {
text += "* ";
}
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n";
}
click: () => {
copyTextByType(ids, "hPath");
if (focusElement) {
focusBlock(focusElement);
}
writeText(text);
}
}, {
id: "copyID",
@ -489,17 +434,7 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
label: window.siyuan.languages.copyID,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
click: () => {
let text = "";
ids.forEach((id, index) => {
if (ids.length > 1) {
text += "* ";
}
text += id;
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n";
}
});
writeText(text);
copyTextByType(ids, "id");
if (focusElement) {
focusBlock(focusElement);
}

View file

@ -1,5 +1,5 @@
/// #if !MOBILE
import {getInstanceById} from "../layout/util";
import {getInstanceById, setPanelFocus} from "../layout/util";
import {Tab} from "../layout/Tab";
import {initSearchMenu} from "./search";
import {initDockMenu} from "./dock";
@ -68,6 +68,7 @@ export class Menus {
this.unselect();
// navigation 根上:新建文档/文件夹/取消挂在/打开文件位置
initNavigationMenu(app, target).popup({x: event.clientX, y: event.clientY});
setPanelFocus(hasClosestByClassName(target, "sy__file") as HTMLElement);
event.stopPropagation();
break;
} else if (dataType === "navigation-file") {
@ -77,6 +78,7 @@ export class Menus {
x: event.clientX,
y: event.clientY
});
setPanelFocus(hasClosestByClassName(target, "sy__file") as HTMLElement);
event.stopPropagation();
break;
} else if (dataType === "search-item") {

View file

@ -54,7 +54,19 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
label: window.siyuan.languages.copy,
type: "submenu",
icon: "iconCopy",
submenu: copySubMenu(blockIDs, false)
submenu: copySubMenu(blockIDs).concat([{
id: "duplicate",
iconHTML: "",
label: window.siyuan.languages.duplicate,
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
click() {
blockIDs.forEach((id) => {
fetchPost("/api/filetree/duplicateDoc", {
id
});
});
}
}])
}).element);
}
@ -481,7 +493,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
label: window.siyuan.languages.copy,
type: "submenu",
icon: "iconCopy",
submenu: (copySubMenu([id], false) as IMenu[]).concat([{
submenu: (copySubMenu([id]) as IMenu[]).concat([{
id: "duplicate",
iconHTML: "",
label: window.siyuan.languages.duplicate,