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 some issues
Adorian Doran73f7e3560fd1
diff --git a/apps/client/src/widgets/react/ScrollableLabel.spec.tsx b/apps/client/src/widgets/react/ScrollableLabel.spec.tsxindex 76d31c958e..5128d013b5 100644--- a/apps/client/src/widgets/react/ScrollableLabel.spec.tsx+++ b/apps/client/src/widgets/react/ScrollableLabel.spec.tsx@@ -115,6 +115,29 @@ describe("ScrollableLabel", () => {}});+ it("keeps the line where the reader left it when the box is resized under them", async () => {+ vi.useFakeTimers();++ try {+ const label = renderLabel("a name the reader takes over", 300, 100, true);++ vi.advanceTimersByTime(1000);+ label.dispatchEvent(new Event("pointerdown", { bubbles: true }));++ const handedOverAt = label.scrollLeft;++ // The box narrows, as it does on a rotation or when a keyboard opens: the line is longer+ // against it than it was, which is what the walk watches for. It must not take it back.+ Object.defineProperty(label, "clientWidth", { value: 60, configurable: true });+ label.dispatchEvent(new Event("scroll"));+ await vi.advanceTimersByTimeAsync(1000);++ expect(label.scrollLeft).toBe(handedOverAt);+ } finally {+ vi.useRealTimers();+ }+ });+it("leaves a label that fits alone, fading nothing", async () => {const label = renderLabel("short", 100);diff --git a/apps/client/src/widgets/react/ScrollableLabel.tsx b/apps/client/src/widgets/react/ScrollableLabel.tsxindex 163cc57124..41258fb472 100644--- a/apps/client/src/widgets/react/ScrollableLabel.tsx+++ b/apps/client/src/widgets/react/ScrollableLabel.tsx@@ -41,8 +41,9 @@ export default function ScrollableLabel({ children, className, autoScroll }: Scr// titles — without asking the caller to say so, and without restarting on a render that changed// nothing (children given as elements rather than as text are a new value every time).const [ overflow, setOverflow ] = useState(0);- // Set by the reader's own first scroll, and cleared only by a new label: a walk they interrupted- // must not start again while the same line is still on screen.+ // Set by the reader's own first scroll, and cleared only by a remount, which is what a new label+ // is: a walk they interrupted must not start again while the same line is still on screen. A+ // consumer whose label changes what it names keys it, so the new one arrives with a fresh walk.const handedOver = useRef(false);const handOver = useCallback(() => {handedOver.current = true;@@ -94,12 +95,13 @@ export default function ScrollableLabel({ children, className, autoScroll }: ScruseEffect(() => {const element = ref.current;- if (!autoScroll || !element || prefersReducedMotion()) {+ // Handed over stays handed over: this effect runs again whenever the line's length changes,+ // and a box resized under the reader — a rotation, a keyboard opening, a pane dragged — must+ // not take the line back off them, which restarting from the beginning would.+ if (!autoScroll || !element || handedOver.current || prefersReducedMotion()) {return;}- // A new label is a new walk, from its own beginning, whatever became of the last one.- handedOver.current = false;element.scrollLeft = 0;// Read once rather than per frame: a right-to-left line travels towards negative offsets, sodiff --git a/apps/client/src/widgets/type_widgets/space_usage/browse.css b/apps/client/src/widgets/type_widgets/space_usage/browse.cssindex d99677a8f6..b15a2762bc 100644--- a/apps/client/src/widgets/type_widgets/space_usage/browse.css+++ b/apps/client/src/widgets/type_widgets/space_usage/browse.css@@ -83,16 +83,14 @@white-space: nowrap;}- /* Reads as the link it is, like the note's name in the middle of the chart. */+ /* The app's own quiet button, coloured to read as the link it stands for — the same colour the+ note's name wears in the middle of the chart. Everything else about it (its press, its focus,+ its theming) is the shared control's. */.space-usage-details-link {overflow: hidden;- border: none;- background: none;- padding: 0;color: var(--link-color);text-overflow: ellipsis;white-space: nowrap;- cursor: pointer;}.space-usage-details-link:hover {diff --git a/apps/client/src/widgets/type_widgets/space_usage/browse.tsx b/apps/client/src/widgets/type_widgets/space_usage/browse.tsxindex 1063fbd72d..1aa48a613c 100644--- a/apps/client/src/widgets/type_widgets/space_usage/browse.tsx+++ b/apps/client/src/widgets/type_widgets/space_usage/browse.tsx@@ -8,6 +8,7 @@ import froca from "../../../services/froca";import { t } from "../../../services/i18n";import { formatSize } from "../../../services/utils";import ActionButton from "../../react/ActionButton";+import Button from "../../react/Button";import type { DonutRing, DonutSegment } from "../../react/charts/DonutChart";import { useFetch } from "../../react/use_fetch";import { type ContentChangedHandler, openSpaceUsageContextMenu } from "./context_menu";@@ -120,7 +121,13 @@ export default function Browse({— so it is swiped rather than cut off, and fades at whichever end it carries onpast. A deep path is otherwise clipped at both ends by a row that centres itself,and the end it loses is the note being looked at. */}- <ScrollableLabel className="space-usage-breadcrumb-track" autoScroll>+ <ScrollableLabel+ // A new path is a new line to read out: keyed so it arrives with its own walk,+ // rather than inheriting one the reader stopped at the level above.+ key={path.join("/")}+ className="space-usage-breadcrumb-track"+ autoScroll+ ><span className="space-usage-crumb-label">{t("space_usage.current_note")}</span>{path.map((id, index) => (<Fragment key={`${index}/${id}`}>@@ -176,11 +183,13 @@ export default function Browse({{onSelect && (<div className="space-usage-browse-details">{selection?.onOpen && (- <button- type="button"+ <ButtonclassName="space-usage-details-link"+ kind="lowProfile"+ size="small"+ text={t("space_usage.show_selection_details")}onClick={selection.onOpen}- >{t("space_usage.show_selection_details")}</button>+ />)}</div>)}