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(popup): keep a list at the caret to one side of the line typed
Elian Doran05de8c156cb9
diff --git a/apps/client/src/widgets/react/Popup.spec.tsx b/apps/client/src/widgets/react/Popup.spec.tsxindex 35c1f0f8ae..41204eac17 100644--- a/apps/client/src/widgets/react/Popup.spec.tsx+++ b/apps/client/src/widgets/react/Popup.spec.tsx@@ -97,6 +97,16 @@ describe("Popup", () => {expect(tall.style.maxHeight).toBe(`${800 - 330 - 5}px`);});+ it("keeps to one side of a caret, never over the line typed, however long it is", async () => {+ vi.spyOn(HTMLElement.prototype, "offsetHeight", "get").mockReturnValue(1000);+ const caret = { getBoundingClientRect: () => DOMRect.fromRect({ x: 100, y: 300, width: 1, height: 16 }) };+ const popup = await open({ anchor: caret });++ // Below the caret, with the room down to the viewport's edge less its gap.+ expect(popup.style.top).toBe("316px");+ expect(popup.style.maxHeight).toBe(`${800 - 316 - 5}px`);+ });+it("keeps clear of the screen's safe areas, such as a notch or a gesture bar", async () => {// The insets a device reports, as the probe reads them from the stylesheet.const measure = window.getComputedStyle.bind(window);diff --git a/apps/client/src/widgets/react/Popup.tsx b/apps/client/src/widgets/react/Popup.tsxindex 04787cb701..3eba1773eb 100644--- a/apps/client/src/widgets/react/Popup.tsx+++ b/apps/client/src/widgets/react/Popup.tsx@@ -120,7 +120,9 @@ export default function Popup({ anchor, placement = "bottom-start", offset: gap// A placement settles after the fact, by which time it can have closed.let closed = false;// Places it now, and again whenever its anchor moves or the viewport or it changes size.- const options = { placement, offset: gap, capHeight, shiftAcross: !(anchor instanceof HTMLElement) };+ // Only a menu at a point moves over it. A rect, such as a caret, marks text the popup must not+ // cover, so the popup keeps to one side and its height is capped to the room there.+ const options = { placement, offset: gap, capHeight, shiftAcross: "x" in anchor };const stopUpdating = autoUpdate(reference, popup, () => void placeFloating(popup, reference, options).then(() => {if (!closed) reportPlaced();// Resolved after the stylesheet took over, so what it wrote goes again.