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/text editor/link editor: tweak UI
Adorian Doran2368cfc0ab9c
diff --git a/apps/client/src/widgets/dialogs/edit_link.css b/apps/client/src/widgets/dialogs/edit_link.cssindex 4e9ccf8782..7a2421714a 100644--- a/apps/client/src/widgets/dialogs/edit_link.css+++ b/apps/client/src/widgets/dialogs/edit_link.css@@ -56,7 +56,7 @@}.edit-link-targets {- height: 240px;+ max-height: 240px;overflow-y: auto;.tn-card-choice {diff --git a/apps/client/src/widgets/dialogs/edit_link.spec.tsx b/apps/client/src/widgets/dialogs/edit_link.spec.tsxindex 5fe14c9849..2f3973eb1d 100644--- a/apps/client/src/widgets/dialogs/edit_link.spec.tsx+++ b/apps/client/src/widgets/dialogs/edit_link.spec.tsx@@ -641,6 +641,7 @@ describe("EditLinkDialog", () => {return { top: isChecked ? 400 - (list?.scrollTop ?? 0) : 0 } as DOMRect;});vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(240);+ vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockReturnValue(640);vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(40);onTestFinished(() => {vi.restoreAllMocks();@@ -657,7 +658,11 @@ describe("EditLinkDialog", () => {expect(headings()).toStrictEqual([ "add_link.headings" ]);expect(checkedHeading()).toBe("Usage");expect(field("text")?.value).toBe("See usage");- expect(container.querySelector(".edit-link-targets")?.scrollTop).toBe(300);+ const list = container.querySelector(".edit-link-targets");+ expect(list?.scrollTop).toBe(300);+ // Rows lie past both edges of the list, so both edges fade.+ expect([ "scroll-fade", "scroll-fade-start", "scroll-fade-end" ]+ .map((name) => list?.classList.contains(name))).toStrictEqual([ true, true, true ]);await submit();expect(addLink).toHaveBeenLastCalledWith("root/note?block=Usage", "See usage");diff --git a/apps/client/src/widgets/dialogs/edit_link.tsx b/apps/client/src/widgets/dialogs/edit_link.tsxindex 539af9caaa..58c301f2ce 100644--- a/apps/client/src/widgets/dialogs/edit_link.tsx+++ b/apps/client/src/widgets/dialogs/edit_link.tsx@@ -3,6 +3,7 @@ import "./edit_link.css";import type { LinkDisplayMode } from "@triliumnext/ckeditor5";import internalLinkIcon from "@triliumnext/ckeditor5/src/icons/trilium.svg?raw";import { ALLOWED_PROTOCOLS, isHttpUrl } from "@triliumnext/commons";+import clsx from "clsx";import { useEffect, useMemo, useRef, useState } from "preact/hooks";import froca from "../../services/froca";@@ -23,6 +24,7 @@ import { suspendModalFocusTraps } from "../react/modal_focustrap";import NoItems from "../react/NoItems";import NoteAutocomplete, { type NoteAutocompleteHandle } from "../react/NoteAutocomplete";import { refToJQuerySelector } from "../react/react_utils";+import { useScrollFade } from "../react/scroll_fade";import SegmentedChoice, { type SegmentedChoiceOption } from "../react/SegmentedChoice";/**@@ -212,6 +214,7 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {const titleRef = useRef<HTMLInputElement>(null);// The scrolling box around the Headings and Anchors cards.const linkTargetsRef = useRef<HTMLDivElement>(null);+ const linkTargetsFade = useScrollFade(linkTargetsRef);const headingTree = useMemo(() => nestHeadings(opts?.headings ?? []), [ opts ]);const initialBookmarkRef = useRef("");// The title of the link preview being edited, while the title field still shows it.@@ -537,7 +540,11 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {const anchorPage = topHeadings.length > 0 || anchors.length > 0 ? (<>{showsTitle && <Card>{titleSection}</Card>}- <div ref={linkTargetsRef} className="edit-link-targets">+ <div+ ref={linkTargetsRef}+ className={clsx("edit-link-targets", linkTargetsFade.className)}+ style={linkTargetsFade.style}+ >{topHeadings.length > 0 && (<Card className="edit-link-headings" heading={t("add_link.headings")}>{topHeadings.map(renderHeadingChoice)}