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/collections/board: fix an issue
Adorian Dorana8814e21c58d
diff --git a/apps/client/src/widgets/react/ScrollableLabel.tsx b/apps/client/src/widgets/react/ScrollableLabel.tsxindex b80801d04e..35c9ff0ba3 100644--- a/apps/client/src/widgets/react/ScrollableLabel.tsx+++ b/apps/client/src/widgets/react/ScrollableLabel.tsx@@ -37,7 +37,12 @@ export default function ScrollableLabel({ children, className, autoScroll }: Scr// The walk below starts over whenever the overflow changes, which is what walks a label whose// words arrived after it did, a path waiting on its titles, without asking the caller to say so// and without restarting on a render that changed nothing.- const { className: fadeClass, overflow } = useScrollFade(ref, { direction: "horizontal" });+ // `minOverflow` is dropped to a pixel: a line cut off by a character still has to read as cut+ // off, and the walk below runs on any overflow at all.+ const { className: fadeClass, overflow } = useScrollFade(ref, {+ direction: "horizontal",+ minOverflow: 1+ });// 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.diff --git a/apps/client/src/widgets/react/scroll_fade.spec.tsx b/apps/client/src/widgets/react/scroll_fade.spec.tsxindex 899a74427f..64365ff717 100644--- a/apps/client/src/widgets/react/scroll_fade.spec.tsx+++ b/apps/client/src/widgets/react/scroll_fade.spec.tsx@@ -84,6 +84,31 @@ describe("useScrollFade", () => {expect(scroller.className).not.toContain("scroll-fade-end");});+ /**+ * A fade reaching 20px into a container that scrolls 2px covers ten times what it hides, and+ * reads as content below that scrolling never reaches.+ */+ it("leaves both ends alone while there is less to scroll than the fade reaches", () => {+ const scroller = setup({ contentSize: 218 });++ expect(scroller.className).not.toContain("scroll-fade-end");++ // Past the fade's own reach, so the fade now stands for something.+ content = 222;+ act(() => {+ scroller.dispatchEvent(new Event("scroll"));+ vi.advanceTimersByTime(20);+ });+ expect(scroller.className).toContain("scroll-fade-end");+ });++ /** A line of text cut off by a character still has to read as cut off. */+ it("fades a smaller overflow for a caller that asks for one", () => {+ const scroller = setup({ contentSize: 205, options: { minOverflow: 1 } });++ expect(scroller.className).toContain("scroll-fade-end");+ });+/** Cards arrive and leave without the box changing size, which no resize reports. */it("measures again when the content changes", async () => {const scroller = setup({ contentSize: 150 });diff --git a/apps/client/src/widgets/react/scroll_fade.ts b/apps/client/src/widgets/react/scroll_fade.tsindex cc4809c649..5b16d7925e 100644--- a/apps/client/src/widgets/react/scroll_fade.ts+++ b/apps/client/src/widgets/react/scroll_fade.ts@@ -10,6 +10,9 @@ import { useTrackedElement } from "./hooks";/** Fractional scroll offsets are reported at sub-pixel precision, so an edge is never tested exactly. */const EDGE_EPSILON = 1;+/** How far a fade reaches from an edge when the caller names no size. Matches `scroll_fade.css`. */+const DEFAULT_FADE_SIZE = 20;+export interface ScrollFadeOptions {/** Which way the container scrolls. */direction?: "horizontal" | "vertical";@@ -17,6 +20,14 @@ export interface ScrollFadeOptions {size?: number;/** How long a fade takes to arrive and to leave, in milliseconds. */duration?: number;+ /**+ * The least a container has to scroll for its edges to be faded at all, in pixels.+ *+ * Defaults to the fade's own size, a fade reaching further than the container can scroll+ * covering more than it hides. Lower it where a few hidden pixels still have to be reported,+ * such as a line of text cut off by a character.+ */+ minOverflow?: number;}export interface ScrollFade {@@ -38,7 +49,9 @@ export interface ScrollFade {* @param options which way it scrolls, how far each fade reaches and how long it takes.*/export function useScrollFade(ref: RefObject<HTMLElement>, options: ScrollFadeOptions = {}): ScrollFade {- const { direction = "vertical", size, duration } = options;+ const {+ direction = "vertical", size, duration, minOverflow = size ?? DEFAULT_FADE_SIZE+ } = options;const [ fades, setFades ] = useState({ start: false, end: false });const [ overflow, setOverflow ] = useState(0);const frameRef = useRef<number>();@@ -58,13 +71,14 @@ export function useScrollFade(ref: RefObject<HTMLElement>, options: ScrollFadeOpsetOverflow(total);setFades((current) => {+ const isFaded = total > minOverflow;const next = {- start: travelled > EDGE_EPSILON,- end: travelled < total - EDGE_EPSILON+ start: isFaded && travelled > EDGE_EPSILON,+ end: isFaded && travelled < total - EDGE_EPSILON};return current.start === next.start && current.end === next.end ? current : next;});- }, [ element, direction ]);+ }, [ element, direction, minOverflow ]);useEffect(() => {if (!element) return;