Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): show a tab left on the tree as such in the switcher

Elian Doran89d4bbe69d8b
diff --git a/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts b/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts
index 48f309e0cf..060d063261 100644
--- a/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts
+++ b/apps/client/src/widgets/mobile_widgets/sidebar_container.spec.ts
@@ -144,6 +144,19 @@ describe("SidebarContainer", () => {
expect(getTabNavigation("first")).toBeUndefined();
});
+ // Restoring tabs at startup and opening a note in a new tab activate the tab without
+ // `activeContextChanged`.
+ it("follows a tab activated together with its note", () => {
+ const sidebar = render(true);
+ const triggerCommand = vi.spyOn(sidebar, "triggerCommand").mockImplementation(() => undefined);
+ const noteContext = { getMainContext: () => ({ ntxId: "opened" }) } as unknown as NoteContext;
+
+ sidebar.noteSwitchedAndActivatedEvent({ noteContext, notePath: "root/note" });
+ expect(triggerCommand).toHaveBeenLastCalledWith("setActiveScreen", { screen: "detail" });
+ sidebar.activeScreenChangedEvent({ activeScreen: "tree" });
+ expect(getTabNavigation("opened")?.screen).toBe("tree");
+ });
+
it("puts the tree back beside the note once the screen widens to a tablet", () => {
const sidebar = render(true);
sidebar.activeScreenChangedEvent({ activeScreen: "tree" });
diff --git a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts b/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
index 9fe53e6a34..0f7ca99d60 100644
--- a/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
+++ b/apps/client/src/widgets/mobile_widgets/sidebar_container.ts
@@ -1,5 +1,6 @@
import type { EventData } from "../../components/app_context.js";
import type { Screen } from "../../components/mobile_screen_switcher.js";
+import type NoteContext from "../../components/note_context.js";
import options from "../../services/options.js";
import { onSystemBack } from "../../services/system_back.js";
import { isNarrowLayout, onNarrowLayoutChange } from "../../services/utils.js";
@@ -208,6 +209,14 @@ export default class SidebarContainer extends FlexContainer<BasicWidget> {
}
activeContextChangedEvent({ noteContext }: EventData<"activeContextChanged">) {
+ this.#switchToTab(noteContext);
+ }
+
+ noteSwitchedAndActivatedEvent({ noteContext }: EventData<"noteSwitchedAndActivated">) {
+ this.#switchToTab(noteContext);
+ }
+
+ #switchToTab(noteContext: NoteContext) {
const tabId = noteContext.getMainContext().ntxId;
if (!tabId || tabId === this.activeTabId) return;
this.activeTabId = tabId;