Skip to content

Build your personal knowledge base with Trilium Notes

feat(tree): tell the two paste actions apart by their icons

Elian Doran9af0a50ecffe
diff --git a/apps/client/src/menus/context_menu.ts b/apps/client/src/menus/context_menu.ts
index 6044bfebb4..c737124f3b 100644
--- a/apps/client/src/menus/context_menu.ts
+++ b/apps/client/src/menus/context_menu.ts
@@ -56,6 +56,11 @@ export interface MenuCommandItem<T> {
* If not set, no icon is displayed and the item will appear shifted slightly to the left if there are other items with icons. To avoid this, use `bx bx-empty`.
*/
uiIcon?: string;
+ /**
+ * A smaller icon set over the bottom corner of {@link uiIcon}, which tells apart items that
+ * share one. Drawn in a row of actions only.
+ */
+ uiIconBadge?: string;
/**
* Classes tinting {@link uiIcon} with the colour of whatever the item stands for, as
* `cssClassManager.createClassForColor()` and `FNote#getColorClass()` return them. Only the
diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts
index fdb117fa48..0e5a697093 100644
--- a/apps/client/src/menus/tree_context_menu.ts
+++ b/apps/client/src/menus/tree_context_menu.ts
@@ -156,13 +156,15 @@ export async function buildTreeContextMenuItems(ctx: TreeContextMenuContext): Pr
title: t("tree-context-menu.paste-into"),
command: "pasteNotesFromClipboard",
keyboardShortcut: "pasteNotesFromClipboard",
- uiIcon: "bx bx-paste",
+ uiIcon: "bx bx-clipboard",
+ uiIconBadge: "bx bx-subdirectory-right",
enabled: !clipboard.isClipboardEmpty() && notSearch && noSelectedNotes
},
{
title: t("tree-context-menu.paste-after"),
command: "pasteNotesAfterFromClipboard",
- uiIcon: "bx bx-paste",
+ uiIcon: "bx bx-clipboard",
+ uiIconBadge: "bx bx-down-arrow-alt",
enabled: !clipboard.isClipboardEmpty() && isNotRoot && !isHoisted && parentNotSearch && noSelectedNotes
},
{
diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.css
index 57bec507d5..cae817d5b1 100644
--- a/apps/client/src/widgets/react/Menu.css
+++ b/apps/client/src/widgets/react/Menu.css
@@ -284,16 +284,30 @@ body.desktop .dropdown-item.dropdown-submenu.submenu-open,
background: var(--menu-item-delimiter-color);
}
- > .tn-icon {
- color: var(--menu-item-icon-color);
- font-size: 1.5em;
- }
-
- &:not(:disabled) > .destructive-action-icon {
+ &:not(:disabled) .destructive-action-icon {
color: var(--dropdown-item-icon-destructive-color);
}
}
+.tn-menu-action-icon {
+ position: relative;
+ display: inline-flex;
+ color: var(--menu-item-icon-color);
+ font-size: 1.5em;
+}
+
+/* The circle must stay centered on `.tn-menu-action-badge`, whose offset and size place it. */
+.tn-menu-action-badged {
+ mask-image: radial-gradient(circle at 80% 80%, transparent 0.36em, #000 0.37em);
+}
+
+.tn-menu-action-badge {
+ position: absolute;
+ right: -0.08em;
+ bottom: -0.08em;
+ font-size: 0.6em;
+}
+
.tn-menu-action-title {
max-width: 100%;
text-align: center;
diff --git a/apps/client/src/widgets/react/Menu.spec.tsx b/apps/client/src/widgets/react/Menu.spec.tsx
index 39b5d1bc90..c710dab9de 100644
--- a/apps/client/src/widgets/react/Menu.spec.tsx
+++ b/apps/client/src/widgets/react/Menu.spec.tsx
@@ -278,7 +278,7 @@ describe("Menu with an action row", () => {
items: [
{ title: "Cut", command: "cut", uiIcon: "bx bx-cut" },
{ title: "Copy", command: "copy", uiIcon: "bx bx-copy", enabled: false },
- { title: "Delete", command: "delete", uiIcon: "bx bx-trash" }
+ { title: "Delete", command: "delete", uiIcon: "bx bx-trash", uiIconBadge: "bx bx-x" }
]
},
{ kind: "separator" },
@@ -316,6 +316,17 @@ describe("Menu with an action row", () => {
expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ command: "cut" }), expect.any(KeyboardEvent));
});
+ it("sets an action's badge over the corner of its icon, which gives way around it", () => {
+ const { menu } = renderMenu();
+ const icons = [ ...menu.querySelectorAll(".tn-menu-action-icon") ].map((icon) =>
+ [ ...icon.children ].map((child) => child.className).join(" + "));
+ expect(icons).toEqual([
+ "tn-icon bx bx-cut",
+ "tn-icon bx bx-copy",
+ "tn-icon bx bx-trash tn-menu-action-badged + tn-menu-action-badge bx bx-x"
+ ]);
+ });
+
it("keeps Right and Left for the submenus on the other rows, mirrored right to left", async () => {
const { menu } = renderMenu();
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index 6e0f178f73..207ebfba1c 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -587,7 +587,10 @@ function MenuAction<T>({ item, onSelect }: { item: MenuCommandItem<T>, onSelect:
onMouseDown={(e) => e.preventDefault()}
onClick={select}
>
- <span className={`tn-icon ${item.uiIcon ?? "bx bx-empty"}`} aria-hidden="true" />
+ <span className="tn-menu-action-icon" aria-hidden="true">
+ <span className={clsx("tn-icon", item.uiIcon ?? "bx bx-empty", item.uiIconBadge && "tn-menu-action-badged")} />
+ {item.uiIconBadge && <span className={clsx("tn-menu-action-badge", item.uiIconBadge)} />}
+ </span>
{/* Callers pass HTML, as for a row's title. */}
<span className="tn-menu-action-title" dangerouslySetInnerHTML={{ __html: item.title }} />
</button>