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): spotlight the active child in a hoisted tree
Elian Doran714fa76a91dc
diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.tsindex 467a3a5f30..e907137554 100644--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts@@ -42,5 +42,9 @@ describe("tab navigation", () => {expect(getSpotlightedNoteId("root/folder", "root/folder")).toBeUndefined();expect(getSpotlightedNoteId("root/folder", "root/folderish/page")).toBeUndefined();expect(getSpotlightedNoteId("root/folder", null)).toBeUndefined();+ // A hoisted tree's columns start at the hoisted note, while the note's path starts at the root.+ expect(getSpotlightedNoteId("folder", "root/folder/inner/leaf")).toBe("inner");+ expect(getSpotlightedNoteId("folder/inner", "root/folder/inner/leaf")).toBe("leaf");+ expect(getSpotlightedNoteId("folder/inner", "root/folder/page")).toBeUndefined();});});diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.tsindex 714437d0e0..ecbd91987b 100644--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.ts@@ -52,11 +52,16 @@ export function getTreeStack(tabId: string | null | undefined, notePath: string/*** The child of the column at `columnPath` that leads to `notePath`, which a column with- * `#subtreeHidden` still lists, as the desktop tree's spotlight does.+ * `#subtreeHidden` still lists, as the desktop tree's spotlight does. A hoisted tree's `columnPath`+ * starts at the hoisted note, so it can match the middle of `notePath`.*/export function getSpotlightedNoteId(columnPath: string | undefined, notePath: string | null | undefined) {- if (!columnPath || !notePath?.startsWith(`${columnPath}/`)) return undefined;- return notePath.slice(columnPath.length + 1).split("/")[0];+ if (!columnPath || !notePath) return undefined;+ const columnIds = columnPath.split("/");+ const noteIds = notePath.split("/");+ const start = noteIds.indexOf(columnIds[0]);+ if (start < 0 || columnIds.some((noteId, index) => noteIds[start + index] !== noteId)) return undefined;+ return noteIds[start + columnIds.length];}export function getLastSegment(notePath: string): string {