Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): spotlight the open note in a hidden subtree

Elian Doran0bf934ed0541
diff --git a/apps/client/src/stylesheets/theme-next/ios.css b/apps/client/src/stylesheets/theme-next/ios.css
index 5b37dd7f25..d720ab4a4e 100644
--- a/apps/client/src/stylesheets/theme-next/ios.css
+++ b/apps/client/src/stylesheets/theme-next/ios.css
@@ -93,6 +93,10 @@ body.mobile.ios {
overflow: hidden;
}
+ .mobile-navigator-current-tile + .mobile-navigator-list {
+ margin-block-start: 22px;
+ }
+
.mobile-navigator-row {
position: relative;
min-height: 52px;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 1dc07ae923..e0745a20c7 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2862,6 +2862,7 @@
"empty": "This note has no children.",
"children_count_one": "{{count}} note",
"children_count_other": "{{count}} notes",
+ "children_hidden": "Child notes are hidden from the tree",
"add_child": "Add child note",
"more_actions": "More actions"
},
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
index e59022110a..48d8cabe77 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.css
@@ -268,6 +268,10 @@
opacity: 0.55;
}
+.mobile-navigator-row.is-spotlighted .mobile-navigator-row-title {
+ font-style: italic;
+}
+
/* Colored notes: `--custom-color` is set by the theme on `.use-note-color`
(see css_class_manager.createClassForColor). Apply it to the title/icon. */
.mobile-navigator-row.use-note-color .mobile-navigator-row-title,
diff --git a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
index bd51d7d1f8..58513d40c8 100644
--- a/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
+++ b/apps/client/src/widgets/mobile_widgets/MobileNoteNavigator.tsx
@@ -30,7 +30,7 @@ import {
} from "../react/hooks";
import Icon from "../react/Icon";
import NoItems from "../react/NoItems";
-import { getLastSegment, getTreeStack, setTabTree } from "./tab_navigation";
+import { getLastSegment, getSpotlightedNoteId, getTreeStack, setTabTree } from "./tab_navigation";
/**
* A touch-native replacement for the Fancytree-based note tree on mobile. Shows one
@@ -113,7 +113,8 @@ export default function MobileNoteNavigator() {
}, [currentParentId, loadedParents]);
const isLoaded = !!currentParentId && loadedParents.has(currentParentId);
- const children = useNavigatorChildren(parentNote, hideArchived, isLoaded, isParentSubtreeHidden);
+ const spotlightedNoteId = getSpotlightedNoteId(currentParentPath, activeNotePath);
+ const children = useNavigatorChildren(parentNote, hideArchived, isLoaded, isParentSubtreeHidden, spotlightedNoteId);
const canGoBack = stack.length > 1;
const backTargetId = canGoBack ? getLastSegment(stack[stack.length - 2]) : undefined;
const backTargetParentId = stack.length >= 3 ? getLastSegment(stack[stack.length - 3]) : undefined;
@@ -314,7 +315,9 @@ export default function MobileNoteNavigator() {
{isLoaded && parentNote && children.length > 0 && (
<div className="mobile-navigator-children-label">
- {t("mobile_note_navigator.children_count", { count: children.length })}
+ {isParentSubtreeHidden
+ ? t("mobile_note_navigator.children_hidden")
+ : t("mobile_note_navigator.children_count", { count: children.length })}
</div>
)}
@@ -330,6 +333,7 @@ export default function MobileNoteNavigator() {
childNotePath={`${currentParentPath}/${child.note.noteId}`}
isActive={child.note.noteId === activeNoteId}
isPending={child.note.noteId === pendingChildId}
+ isSpotlighted={isParentSubtreeHidden}
hideArchived={hideArchived}
onDrill={drillInto}
onOpen={openNotePath}
@@ -406,13 +410,14 @@ interface NavigatorRowProps {
childNotePath: string;
isActive: boolean;
isPending: boolean;
+ isSpotlighted: boolean;
hideArchived: boolean;
onDrill: (notePath: string) => void;
onOpen: (notePath: string) => void;
parentComponent: Component | null;
}
-function NavigatorRow({ note, parentNoteId, childNotePath, isActive, isPending, hideArchived, onDrill, onOpen, parentComponent }: NavigatorRowProps) {
+function NavigatorRow({ note, parentNoteId, childNotePath, isActive, isPending, isSpotlighted, hideArchived, onDrill, onOpen, parentComponent }: NavigatorRowProps) {
const icon = useNoteIcon(note);
const [isSubtreeHidden] = useNoteLabelBoolean(note, "subtreeHidden");
const rawChildCount = note.getChildNoteIds().length;
@@ -435,6 +440,7 @@ function NavigatorRow({ note, parentNoteId, childNotePath, isActive, isPending,
"is-active": isActive,
"is-archived": note.isArchived,
"is-pending": isPending,
+ "is-spotlighted": isSpotlighted,
"has-children": hasChildren
})}
role="button"
@@ -487,7 +493,8 @@ export function useNavigatorChildren(
parentNote: FNote | null | undefined,
hideArchived: boolean,
isLoaded: boolean,
- isParentSubtreeHidden: boolean
+ isParentSubtreeHidden: boolean,
+ spotlightedNoteId: string | undefined
): NavigatorChild[] {
const [children, setChildren] = useState<NavigatorChild[]>([]);
// Re-run when the parent's child list mutates in place (e.g., a new branch is added by
@@ -496,12 +503,15 @@ export function useNavigatorChildren(
const childrenKey = parentNote?.children?.join(",");
useEffect(() => {
- if (!parentNote || !isLoaded || isParentSubtreeHidden) {
+ if (!parentNote || !isLoaded || (isParentSubtreeHidden && !spotlightedNoteId)) {
setChildren([]);
return;
}
let cancelled = false;
- const branches = parentNote.getChildBranches().filter((b): b is NonNullable<typeof b> => !!b);
+ // A parent with `#subtreeHidden` lists only the child on the active note's path.
+ const branches = parentNote.getChildBranches()
+ .filter((b): b is NonNullable<typeof b> => !!b)
+ .filter((b) => !isParentSubtreeHidden || b.noteId === spotlightedNoteId);
// Use the async loader so notes that aren't yet in cache (e.g., freshly created via "+")
// are pulled in. `processNoteChange` only updates notes already in froca, so without this
// newly-created child notes would be silently skipped.
@@ -519,7 +529,7 @@ export function useNavigatorChildren(
setChildren(result);
});
return () => { cancelled = true; };
- }, [parentNote, childrenKey, hideArchived, isLoaded, isParentSubtreeHidden]);
+ }, [parentNote, childrenKey, hideArchived, isLoaded, isParentSubtreeHidden, spotlightedNoteId]);
return children;
}
diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.spec.tsx b/apps/client/src/widgets/mobile_widgets/TabSwitcher.spec.tsx
index 5b6c05909b..76c345615a 100644
--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.spec.tsx
+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.spec.tsx
@@ -13,6 +13,10 @@ describe("Tab", () => {
{ id: "folder", title: "Folder", children: [
{ id: "first", title: "First" },
{ id: "second", title: "Second" }
+ ] },
+ { id: "collection", title: "Collection", "#subtreeHidden": "", children: [
+ { id: "shown", title: "Shown" },
+ { id: "spotlit", title: "Spotlit" }
] }
]);
@@ -64,6 +68,27 @@ describe("Tab", () => {
expect(card.querySelector(".tab-preview-placeholder")).toBeNull();
});
+ it("lists only the child on the tab's note path in a column whose subtree is hidden", async () => {
+ setTabTree("in-collection", { notePath: "root/collection/spotlit", hoistedNoteId: "root", stack: [ "root", "root/collection" ] });
+ setTabScreen("in-collection", "tree");
+
+ const card = await renderTab("in-collection");
+ const rows = await vi.waitFor(() => {
+ const rows = [ ...card.querySelectorAll(".tab-preview.type-tree .tree-row") ];
+ expect(rows).toHaveLength(1);
+ return rows;
+ });
+ expect(rows[0].textContent).toBe("Spotlit");
+ expect(rows[0].classList.contains("active")).toBe(true);
+ expect(card.querySelector(".tab-preview-placeholder")).toBeNull();
+
+ setTabTree("off-collection", { notePath: "root/folder/second", hoistedNoteId: "root", stack: [ "root", "root/collection" ] });
+ setTabScreen("off-collection", "tree");
+ const offCard = await renderTab("off-collection");
+ expect(offCard.querySelector(".tab-preview-placeholder")).not.toBeNull();
+ expect(offCard.querySelectorAll(".tree-row")).toHaveLength(0);
+ });
+
it("shows the note of a tab left on it, and on a tablet whatever the tab was left on", async () => {
setTabTree("on-note", { notePath: "root/folder/second", hoistedNoteId: "root", stack: [ "root", "root/folder" ] });
setTabScreen("on-note", "detail");
diff --git a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
index 279decd750..0c319adfca 100644
--- a/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
+++ b/apps/client/src/widgets/mobile_widgets/TabSwitcher.tsx
@@ -31,7 +31,7 @@ import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
import Modal from "../react/Modal";
import { useNavigatorChildren } from "./MobileNoteNavigator";
-import { getLastSegment, getTabNavigation, type TreeStack } from "./tab_navigation";
+import { getLastSegment, getSpotlightedNoteId, getTabNavigation, type TreeStack } from "./tab_navigation";
const VIEW_MODE_ICON_MAPPINGS: Record<Exclude<ViewMode, "default">, string> = {
source: "bx bx-code",
@@ -204,9 +204,10 @@ function TreeTabContent({ noteContext, tree }: { noteContext: NoteContext, tree:
const title = useNoteTitle(columnNoteId, columnParentId);
const [ hideArchived ] = useTriliumOptionBool("hideArchivedNotes_main");
const [ isSubtreeHidden ] = useNoteLabelBoolean(columnNote, "subtreeHidden");
- const rows = useNavigatorChildren(columnNote, hideArchived, true, isSubtreeHidden).slice(0, MAX_TREE_PREVIEW_ROWS);
+ const spotlightedNoteId = getSpotlightedNoteId(columnPath, tree.notePath);
+ const rows = useNavigatorChildren(columnNote, hideArchived, true, isSubtreeHidden, spotlightedNoteId).slice(0, MAX_TREE_PREVIEW_ROWS);
const activeNoteId = tree.notePath ? getLastSegment(tree.notePath) : undefined;
- const isEmpty = isSubtreeHidden || !columnNote?.getChildNoteIds().length;
+ const isEmpty = isSubtreeHidden ? !spotlightedNoteId : !columnNote?.getChildNoteIds().length;
return (
<>
diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
index 5fd4c9d9a7..467a3a5f30 100644
--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.spec.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { buildNotes } from "../../test/easy-froca";
-import { forgetTabs, getTabNavigation, getTreeStack, setTabScreen, setTabTree } from "./tab_navigation";
+import { forgetTabs, getSpotlightedNoteId, getTabNavigation, getTreeStack, setTabScreen, setTabTree } from "./tab_navigation";
describe("tab navigation", () => {
buildNotes([
@@ -35,4 +35,12 @@ describe("tab navigation", () => {
forgetTabs([ "closing" ]);
expect(getTabNavigation("closing")).toBeUndefined();
});
+
+ it("spotlights the child of a column that leads to the tab's note", () => {
+ expect(getSpotlightedNoteId("root/folder", "root/folder/inner/leaf")).toBe("inner");
+ expect(getSpotlightedNoteId("root/folder", "root/folder/page")).toBe("page");
+ expect(getSpotlightedNoteId("root/folder", "root/folder")).toBeUndefined();
+ expect(getSpotlightedNoteId("root/folder", "root/folderish/page")).toBeUndefined();
+ expect(getSpotlightedNoteId("root/folder", null)).toBeUndefined();
+ });
});
diff --git a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts b/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
index 8192fcab7c..714437d0e0 100644
--- a/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
+++ b/apps/client/src/widgets/mobile_widgets/tab_navigation.ts
@@ -50,6 +50,15 @@ export function getTreeStack(tabId: string | null | undefined, notePath: string
return buildStackForActiveNote(notePath, hoistedNoteId);
}
+/**
+ * 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.
+ */
+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];
+}
+
export function getLastSegment(notePath: string): string {
const idx = notePath.lastIndexOf("/");
return idx >= 0 ? notePath.slice(idx + 1) : notePath;