This commit is contained in:
parent
646d4b8ab0
commit
36df3d5ea1
7 changed files with 100 additions and 27 deletions
|
@ -60,7 +60,7 @@ export const openBookmarkMenu = (element: HTMLElement, event: MouseEvent, bookma
|
|||
label: window.siyuan.languages.copy,
|
||||
type: "submenu",
|
||||
icon: "iconCopy",
|
||||
submenu: copySubMenu(element.getAttribute("data-node-id"), false)
|
||||
submenu: copySubMenu([element.getAttribute("data-node-id")], false)
|
||||
}).element);
|
||||
}
|
||||
|
||||
|
|
|
@ -371,16 +371,27 @@ export const openAttr = (nodeElement: Element, focusName = "bookmark", protyle?:
|
|||
});
|
||||
};
|
||||
|
||||
export const copySubMenu = (id: string, accelerator = true, focusElement?: Element) => {
|
||||
export const copySubMenu = (ids: string[], accelerator = true, focusElement?: Element) => {
|
||||
return [{
|
||||
id: "copyBlockRef",
|
||||
iconHTML: "",
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
|
||||
label: window.siyuan.languages.copyBlockRef,
|
||||
click: () => {
|
||||
fetchPost("/api/block/getRefText", {id}, (response) => {
|
||||
writeText(`((${id} '${response.data}'))`);
|
||||
});
|
||||
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);
|
||||
if (focusElement) {
|
||||
focusBlock(focusElement);
|
||||
}
|
||||
|
@ -391,7 +402,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
label: window.siyuan.languages.copyBlockEmbed,
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
|
||||
click: () => {
|
||||
writeText(`{{select * from blocks where id='${id}'}}`);
|
||||
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);
|
||||
if (focusElement) {
|
||||
focusBlock(focusElement);
|
||||
}
|
||||
|
@ -402,7 +423,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
label: window.siyuan.languages.copyProtocol,
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
|
||||
click: () => {
|
||||
writeText(`siyuan://blocks/${id}`);
|
||||
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);
|
||||
if (focusElement) {
|
||||
focusBlock(focusElement);
|
||||
}
|
||||
|
@ -412,10 +443,21 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
iconHTML: "",
|
||||
label: window.siyuan.languages.copyProtocolInMd,
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined,
|
||||
click: () => {
|
||||
fetchPost("/api/block/getRefText", {id}, (response) => {
|
||||
writeText(`[${response.data}](siyuan://blocks/${id})`);
|
||||
});
|
||||
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);
|
||||
if (focusElement) {
|
||||
focusBlock(focusElement);
|
||||
}
|
||||
|
@ -425,12 +467,21 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
iconHTML: "",
|
||||
label: window.siyuan.languages.copyHPath,
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
|
||||
click: () => {
|
||||
fetchPost("/api/filetree/getHPathByID", {
|
||||
id
|
||||
}, (response) => {
|
||||
writeText(response.data);
|
||||
});
|
||||
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";
|
||||
}
|
||||
}
|
||||
writeText(text);
|
||||
}
|
||||
}, {
|
||||
id: "copyID",
|
||||
|
@ -438,7 +489,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
label: window.siyuan.languages.copyID,
|
||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
|
||||
click: () => {
|
||||
writeText(id);
|
||||
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);
|
||||
if (focusElement) {
|
||||
focusBlock(focusElement);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
|||
if (!fileItemElement) {
|
||||
return window.siyuan.menus.menu;
|
||||
}
|
||||
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
||||
Array.from(selectItemElements)
|
||||
)));
|
||||
const blockIDs: string[] = [];
|
||||
selectItemElements.forEach(item => {
|
||||
const id = item.getAttribute("data-node-id");
|
||||
|
@ -50,6 +47,21 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
|||
blockIDs.push(id);
|
||||
}
|
||||
});
|
||||
|
||||
if (blockIDs.length > 0) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
id: "copy",
|
||||
label: window.siyuan.languages.copy,
|
||||
type: "submenu",
|
||||
icon: "iconCopy",
|
||||
submenu: copySubMenu(blockIDs, false)
|
||||
}).element);
|
||||
}
|
||||
|
||||
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
||||
Array.from(selectItemElements)
|
||||
)));
|
||||
|
||||
if (blockIDs.length > 0) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
id: "addToDatabase",
|
||||
|
@ -469,7 +481,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], false) as IMenu[]).concat([{
|
||||
id: "duplicate",
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.duplicate,
|
||||
|
|
|
@ -6,7 +6,7 @@ export const initSearchMenu = (id: string) => {
|
|||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.copy,
|
||||
type: "submenu",
|
||||
submenu: copySubMenu(id)
|
||||
submenu: copySubMenu([id])
|
||||
}).element);
|
||||
return window.siyuan.menus.menu;
|
||||
};
|
||||
|
|
|
@ -206,7 +206,7 @@ export const initTabMenu = (app: App, tab: Tab) => {
|
|||
label: window.siyuan.languages.copy,
|
||||
icon: "iconCopy",
|
||||
type: "submenu",
|
||||
submenu: copySubMenu(rootId, false)
|
||||
submenu: copySubMenu([rootId], false)
|
||||
}).element);
|
||||
} else if (model && model instanceof Asset) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
@ -1260,7 +1260,7 @@ export class Gutter {
|
|||
}).element);
|
||||
}
|
||||
|
||||
const copyMenu = (copySubMenu(id, true, nodeElement) as IMenu[]).concat([{
|
||||
const copyMenu = (copySubMenu([id], true, nodeElement) as IMenu[]).concat([{
|
||||
id: "copyPlainText",
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.copyPlainText,
|
||||
|
|
|
@ -42,7 +42,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
|||
label: window.siyuan.languages.copy,
|
||||
icon: "iconCopy",
|
||||
type: "submenu",
|
||||
submenu: copySubMenu(protyle.block.rootID)
|
||||
submenu: copySubMenu([protyle.block.rootID])
|
||||
}).element);
|
||||
if (!protyle.disabled) {
|
||||
window.siyuan.menus.menu.append(movePathToMenu([protyle.path]));
|
||||
|
|
Loading…
Add table
Reference in a new issue