mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
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,
|
label: window.siyuan.languages.copy,
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: "iconCopy",
|
icon: "iconCopy",
|
||||||
submenu: copySubMenu(element.getAttribute("data-node-id"), false)
|
submenu: copySubMenu([element.getAttribute("data-node-id")], false)
|
||||||
}).element);
|
}).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 [{
|
return [{
|
||||||
id: "copyBlockRef",
|
id: "copyBlockRef",
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
|
||||||
label: window.siyuan.languages.copyBlockRef,
|
label: window.siyuan.languages.copyBlockRef,
|
||||||
click: () => {
|
click: async () => {
|
||||||
fetchPost("/api/block/getRefText", {id}, (response) => {
|
let text = "";
|
||||||
writeText(`((${id} '${response.data}'))`);
|
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) {
|
if (focusElement) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
}
|
}
|
||||||
|
|
@ -391,7 +402,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
||||||
label: window.siyuan.languages.copyBlockEmbed,
|
label: window.siyuan.languages.copyBlockEmbed,
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
|
||||||
click: () => {
|
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) {
|
if (focusElement) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
}
|
}
|
||||||
|
|
@ -402,7 +423,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
||||||
label: window.siyuan.languages.copyProtocol,
|
label: window.siyuan.languages.copyProtocol,
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
|
||||||
click: () => {
|
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) {
|
if (focusElement) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
}
|
}
|
||||||
|
|
@ -412,10 +443,21 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: window.siyuan.languages.copyProtocolInMd,
|
label: window.siyuan.languages.copyProtocolInMd,
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined,
|
||||||
click: () => {
|
click: async () => {
|
||||||
fetchPost("/api/block/getRefText", {id}, (response) => {
|
let text = "";
|
||||||
writeText(`[${response.data}](siyuan://blocks/${id})`);
|
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) {
|
if (focusElement) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
}
|
}
|
||||||
|
|
@ -425,12 +467,21 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: window.siyuan.languages.copyHPath,
|
label: window.siyuan.languages.copyHPath,
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
|
||||||
click: () => {
|
click: async () => {
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
let text = "";
|
||||||
id
|
for (let i = 0; i < ids.length; i++) {
|
||||||
}, (response) => {
|
const id = ids[i];
|
||||||
writeText(response.data);
|
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",
|
id: "copyID",
|
||||||
|
|
@ -438,7 +489,17 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
||||||
label: window.siyuan.languages.copyID,
|
label: window.siyuan.languages.copyID,
|
||||||
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
|
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
|
||||||
click: () => {
|
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) {
|
if (focusElement) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,6 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
||||||
if (!fileItemElement) {
|
if (!fileItemElement) {
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
|
||||||
Array.from(selectItemElements)
|
|
||||||
)));
|
|
||||||
const blockIDs: string[] = [];
|
const blockIDs: string[] = [];
|
||||||
selectItemElements.forEach(item => {
|
selectItemElements.forEach(item => {
|
||||||
const id = item.getAttribute("data-node-id");
|
const id = item.getAttribute("data-node-id");
|
||||||
|
|
@ -50,6 +47,21 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
|
||||||
blockIDs.push(id);
|
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) {
|
if (blockIDs.length > 0) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
id: "addToDatabase",
|
id: "addToDatabase",
|
||||||
|
|
@ -469,7 +481,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
|
||||||
label: window.siyuan.languages.copy,
|
label: window.siyuan.languages.copy,
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: "iconCopy",
|
icon: "iconCopy",
|
||||||
submenu: (copySubMenu(id, false) as IMenu[]).concat([{
|
submenu: (copySubMenu([id], false) as IMenu[]).concat([{
|
||||||
id: "duplicate",
|
id: "duplicate",
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: window.siyuan.languages.duplicate,
|
label: window.siyuan.languages.duplicate,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export const initSearchMenu = (id: string) => {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.copy,
|
label: window.siyuan.languages.copy,
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
submenu: copySubMenu(id)
|
submenu: copySubMenu([id])
|
||||||
}).element);
|
}).element);
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ export const initTabMenu = (app: App, tab: Tab) => {
|
||||||
label: window.siyuan.languages.copy,
|
label: window.siyuan.languages.copy,
|
||||||
icon: "iconCopy",
|
icon: "iconCopy",
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
submenu: copySubMenu(rootId, false)
|
submenu: copySubMenu([rootId], false)
|
||||||
}).element);
|
}).element);
|
||||||
} else if (model && model instanceof Asset) {
|
} else if (model && model instanceof Asset) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
|
||||||
|
|
@ -1260,7 +1260,7 @@ export class Gutter {
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyMenu = (copySubMenu(id, true, nodeElement) as IMenu[]).concat([{
|
const copyMenu = (copySubMenu([id], true, nodeElement) as IMenu[]).concat([{
|
||||||
id: "copyPlainText",
|
id: "copyPlainText",
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: window.siyuan.languages.copyPlainText,
|
label: window.siyuan.languages.copyPlainText,
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
||||||
label: window.siyuan.languages.copy,
|
label: window.siyuan.languages.copy,
|
||||||
icon: "iconCopy",
|
icon: "iconCopy",
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
submenu: copySubMenu(protyle.block.rootID)
|
submenu: copySubMenu([protyle.block.rootID])
|
||||||
}).element);
|
}).element);
|
||||||
if (!protyle.disabled) {
|
if (!protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(movePathToMenu([protyle.path]));
|
window.siyuan.menus.menu.append(movePathToMenu([protyle.path]));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue