Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doran6338c5a0ccce
diff --git a/apps/client/src/widgets/collections/board/card.spec.tsx b/apps/client/src/widgets/collections/board/card.spec.tsx
index 94b2fc6b7f..5eb6f6fbe6 100644
--- a/apps/client/src/widgets/collections/board/card.spec.tsx
+++ b/apps/client/src/widgets/collections/board/card.spec.tsx
@@ -75,6 +75,20 @@ describe("Board card", () => {
expect(openInPopup).toHaveBeenCalledTimes(2);
});
+ it("opens the note once for a double click, not once per click of it", async () => {
+ const { first } = await renderBoard();
+ const openInPopup = vi.spyOn(appContext, "triggerCommand").mockReturnValue(undefined);
+ const element = card(first);
+
+ // What a browser sends for a double click: the same event twice, counted by `detail`.
+ await act(async () => {
+ element.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 }));
+ element.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 2 }));
+ });
+
+ expect(openInPopup).toHaveBeenCalledTimes(1);
+ });
+
it("puts its title into the editor from its button and from F2, and saves it", async () => {
const { first } = await renderBoard();
const put = vi.spyOn(server, "put").mockResolvedValue(undefined);
diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx
index 42f607a477..7076c7efad 100644
--- a/apps/client/src/widgets/collections/board/card.tsx
+++ b/apps/client/src/widgets/collections/board/card.tsx
@@ -73,7 +73,11 @@ function Card({
openNoteContextMenu(api, e, note, branch.branchId, column);
}, [ api, note, branch, column ]);
- const handleOpen = useCallback(() => {
+ const handleOpen = useCallback((e: MouseEvent) => {
+ // A double click is one gesture, and its second click would open the note over itself: the
+ // popup already standing is taken as the one to stack on, and closing that leaves neither.
+ if (e.detail > 1) return;
+
api.openNote(note.noteId);
}, [ api, note ]);