Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): open the note menu on its shortcut only in the active context
Elian Doranb00e42966469
diff --git a/apps/client/src/widgets/layout/NoteActions.spec.tsx b/apps/client/src/widgets/layout/NoteActions.spec.tsxindex efd45bf057..84deec4b4d 100644--- a/apps/client/src/widgets/layout/NoteActions.spec.tsx+++ b/apps/client/src/widgets/layout/NoteActions.spec.tsx@@ -1,4 +1,5 @@import { render } from "preact";+import { act } from "preact/test-utils";import { afterEach, describe, expect, it, vi } from "vitest";import Component from "../../components/component";@@ -118,4 +119,26 @@ describe("NoteContextMenu", () => {expect((await shownIn("_popup-editor", image)).paperclips).toBe(1);}});++ it("opens on the Basic Properties shortcut only for its own note context", async () => {+ const note = buildNote({ title: "Text", type: "text", content: "<p>Hi</p>" });+ const noteContext = new NoteContext("ntx-split-2");+ noteContext.noteId = note.noteId;+ noteContext.viewScope = { viewMode: "default" };+ const parent = new Component();+ render((+ <ParentComponent.Provider value={parent}>+ <NoteContextContext.Provider value={noteContext}>+ <NoteContextMenu note={note} noteContext={noteContext} />+ </NoteContextContext.Provider>+ </ParentComponent.Provider>+ ), host);+ const popup = () => document.querySelector(".tn-popup");++ await act(async () => { await parent.handleEvent("toggleRibbonTabBasicProperties", { ntxId: "ntx-split-1" }); });+ expect(popup()).toBeNull();++ await act(async () => { await parent.handleEvent("toggleRibbonTabBasicProperties", { ntxId: "ntx-split-2" }); });+ await vi.waitFor(() => expect(popup()).not.toBeNull());+ });});diff --git a/apps/client/src/widgets/layout/NoteActions.tsx b/apps/client/src/widgets/layout/NoteActions.tsxindex 7b9c7f7e52..88dc664622 100644--- a/apps/client/src/widgets/layout/NoteActions.tsx+++ b/apps/client/src/widgets/layout/NoteActions.tsx@@ -90,7 +90,8 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNoteconst isInPopup = !!noteContext?.ntxId?.startsWith(POPUP_EDITOR_NTX_ID);const itemToFocusRef = useRef<ItemToFocus>(null);// Keyboard shortcuts.- useTriliumEvent("toggleRibbonTabBasicProperties", () => {+ useTriliumEvent("toggleRibbonTabBasicProperties", ({ ntxId }) => {+ if (!noteContext || ntxId !== noteContext.ntxId) return;itemToFocusRef.current = "basic-properties";dropdownRef.current?.toggle();});