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(mobile): enter a workspace on the tree, not on its note
Elian Doran7bbf24fbba0f
diff --git a/apps/client/src/components/note_context.spec.ts b/apps/client/src/components/note_context.spec.tsindex c1e603c2f9..32b3a759a4 100644--- a/apps/client/src/components/note_context.spec.ts+++ b/apps/client/src/components/note_context.spec.ts@@ -1,6 +1,7 @@-import { beforeEach, describe, expect, it } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { ViewScope } from "../services/link.js";+import utils from "../services/utils.js";import { buildNote } from "../test/easy-froca.js";import appContext from "./app_context.js";import NoteContext from "./note_context.js";@@ -132,3 +133,35 @@ describe("NoteContext view scope", () => {expect(noteContext.viewScope).toEqual({ viewMode: "default", bookmark: "intro" });});});++describe("NoteContext on a phone", () => {+ // `tree.resolveNotePath()` reads the active note path from the tab manager.+ const { tabManager } = appContext;+ beforeEach(() => {+ appContext.tabManager = { getActiveContextNotePath: () => null } as unknown as TabManager;+ });+ afterEach(() => {+ appContext.tabManager = tabManager;+ vi.restoreAllMocks();+ });++ it("shows a note it opens, but stays on the tree when hoisting opens one", async () => {+ buildNote({ id: "root", title: "root", children: [+ { id: "elsewhere", title: "Elsewhere" },+ { id: "workspace", title: "Workspace", "#workspace": "", children: [ { id: "inside", title: "Inside" } ] }+ ] });+ vi.spyOn(utils, "isMobile").mockReturnValue(true);+ const noteContext = new NoteContext();+ const triggerCommand = vi.spyOn(noteContext, "triggerCommand");+ const screenSwitches = () => triggerCommand.mock.calls.filter(([ name ]) => name === "setActiveScreen");++ await noteContext.setNote("root/elsewhere", { skipRecentNotes: true, triggerSwitchEvent: false });+ expect(screenSwitches()).toEqual([ [ "setActiveScreen", { screen: "detail" } ] ]);++ triggerCommand.mockClear();+ // The open note lies outside the workspace, so hoisting opens the workspace note.+ await noteContext.setHoistedNoteId("workspace");+ expect(noteContext.notePath).toBe("root/workspace");+ expect(screenSwitches()).toEqual([]);+ });+});diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.tsindex d2d0ec0d41..e0d6244b67 100644--- a/apps/client/src/components/note_context.ts+++ b/apps/client/src/components/note_context.ts@@ -29,6 +29,8 @@ export interface SetNoteOpts {skipRecentNotes?: boolean;/** The `switchToHistoryEntry()` call that shows the note. Pinned tabs pass it on. */historyEntry?: HistoryEntry;+ /** If true, the mobile layout stays on the screen it shows instead of switching to the note. */+ keepScreen?: boolean;}export type GetTextEditorCallback = (editor: CKTextEditor) => void;@@ -251,7 +253,7 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">await this.setHoistedNoteIfNeeded();- if (utils.isMobile()) {+ if (utils.isMobile() && !opts.keepScreen) {this.triggerCommand("setActiveScreen", { screen: "detail" });}@@ -394,8 +396,10 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">this.hoistedNoteId = noteIdToHoist;+ // The hoisted note replaces one outside it without being opened on purpose, so a phone+ // showing the tree keeps showing it.if (!this.notePathArray?.includes(noteIdToHoist)) {- await this.setNote(noteIdToHoist);+ await this.setNote(noteIdToHoist, { keepScreen: true });}await this.triggerEvent("hoistedNoteChanged", {