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
client: fix an issue
Adorian Doranf25da2df10b7
diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.tsindex 86606b18cb..72c86f2c22 100644--- a/apps/client/src/components/note_context.ts+++ b/apps/client/src/components/note_context.ts@@ -201,7 +201,8 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">return appContext.tabManager.openContextWithNote(resolvedNotePath, {activate: true,viewScope,- hoistedNoteId: this.hoistedNoteId+ hoistedNoteId: this.hoistedNoteId,+ redirectedFrom: this});}diff --git a/apps/client/src/components/tab_manager.spec.ts b/apps/client/src/components/tab_manager.spec.tsindex 3f2b5a612e..122f59a53f 100644--- a/apps/client/src/components/tab_manager.spec.ts+++ b/apps/client/src/components/tab_manager.spec.ts@@ -380,6 +380,25 @@ describe("going to an entry of the navigation history", () => {expect(window.location.hash).toBe(`#root/historyA?ntxId=${reopened?.ntxId}`);});+ it("rewrites the entry of a pinned tab with the tab it opens instead", async () => {+ const pinnedTab = await tm.openEmptyTab();+ await tm.activateNoteContext(pinnedTab.ntxId);+ await pinnedTab.setNote("root/historyA");+ await pinnedTab.setNote("root/historyB");+ pinnedTab.pinned = true;++ window.history.replaceState(null, "", `#root/historyA?ntxId=${pinnedTab.ntxId}`);+ const pushState = vi.spyOn(window.history, "pushState");++ await tm.switchToHistoryEntry(pinnedTab.ntxId, "root/historyA", { viewMode: "default" });++ expect(pushState).not.toHaveBeenCalled();+ const opened = tm.getActiveContext();+ expect(opened).not.toBe(pinnedTab);+ expect(pinnedTab.notePath).toBe("root/historyB");+ expect(window.location.hash).toBe(`#root/historyA?ntxId=${opened?.ntxId}`);+ });+it("pushes a tab switch made while the entry is still loading", async () => {const first = await tm.openEmptyTab();const second = await tm.openEmptyTab();diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.tsindex 8b54f7e0c9..3d9c14605a 100644--- a/apps/client/src/components/tab_manager.ts+++ b/apps/client/src/components/tab_manager.ts@@ -37,7 +37,7 @@ export default class TabManager extends Component {public activeNtxId: string | null;public recentlyClosedTabs: TabState[];public tabsUpdate: SpacedUpdate;- /** The note context that the latest `switchToHistoryEntry()` call shows. */+ /** The note context that shows the entry of the latest `switchToHistoryEntry()` call. */private historyEntry: { noteContext: NoteContext } | null = null;constructor() {@@ -470,6 +470,8 @@ export default class TabManager extends Component {pinned?: boolean | null;/** Where the new tab is placed in the row. Defaults to `"end"`; link/middle-click opens pass `"afterCurrent"`. */placement?: TabPlacement | null;+ /** The pinned note context whose navigation opens this tab. */+ redirectedFrom?: NoteContext | null;} = {}): Promise<NoteContext> {const activate = !!opts.activate;@@ -494,6 +496,11 @@ export default class TabManager extends Component {}if (activate && noteContext.notePath) {+ // The new tab continues the navigation of the history entry it was redirected from.+ if (opts.redirectedFrom && this.historyEntry?.noteContext === opts.redirectedFrom) {+ this.historyEntry.noteContext = noteContext;+ }+this.activateNoteContext(noteContext.ntxId, false);await this.triggerEvent("noteSwitchedAndActivated", {