Skip to content

Commit

Permalink
🎨 #11561
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 20, 2024
1 parent 646d4b8 commit 36df3d5
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/src/menus/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
97 changes: 79 additions & 18 deletions app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -425,20 +467,39 @@ 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",
iconHTML: "",
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);
}
Expand Down
20 changes: 16 additions & 4 deletions app/src/menus/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,28 @@ 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");
if (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) {
window.siyuan.menus.menu.append(new MenuItem({
id: "addToDatabase",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/src/menus/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion app/src/menus/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/header/openTitleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down

0 comments on commit 36df3d5

Please sign in to comment.