Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(web): correct mobile keyboard popover positioning (#572)
Generf8388eccf6cf
diff --git a/src/web/src/hooks/use-anchored-popover.test.ts b/src/web/src/hooks/use-anchored-popover.test.tsindex 12dc87e85..fd6d4cdbc 100644--- a/src/web/src/hooks/use-anchored-popover.test.ts+++ b/src/web/src/hooks/use-anchored-popover.test.ts@@ -14,18 +14,16 @@ function rect(top: number, left: number, height = 16): AnchorRect {}describe("anchoredPopoverStyle", () => {- it("converts visual coordinates to layout-fixed coordinates exactly once", () => {+ it("keeps layout coordinates unchanged inside a non-zero visual viewport", () => {const style = anchoredPopoverStyle(rect(400, 40), VIEWPORT, 256, 240)- expect(style.top).toBe(496)- expect(style.left).toBe(60)- expect(Number(style.top) - VIEWPORT.top).toBe(396)- expect(Number(style.left) - VIEWPORT.left).toBe(40)+ expect(style.top).toBe(396)+ expect(style.left).toBe(40)expect(style.transform).toBe("translateY(-100%)")expect(style["--anchored-popover-max-height"]).toBe("240px")})it("flips below a caret near the visual viewport top", () => {- const style = anchoredPopoverStyle(rect(20, 40), VIEWPORT, 256, 240)+ const style = anchoredPopoverStyle(rect(120, 40), VIEWPORT, 256, 240)expect(style.top).toBe(140)expect(Number(style.top) - VIEWPORT.top).toBe(40)expect(style.transform).toBeUndefined()@@ -38,11 +36,26 @@ describe("anchoredPopoverStyle", () => {it("uses the roomier side and reduces list height when neither side fully fits", () => {const shortViewport = { top: 100, left: 0, width: 320, height: 220 }- const style = anchoredPopoverStyle(rect(80, 20), shortViewport, 256, 240)+ const style = anchoredPopoverStyle(rect(180, 20), shortViewport, 256, 240)expect(style.transform).toBeUndefined()expect(style["--anchored-popover-max-height"]).toBe("102px")})+ it("does not add the keyboard-panned viewport offset to the fixed anchor", () => {+ const keyboardViewport = { top: 364, left: 0, width: 390, height: 480 }+ const style = anchoredPopoverStyle(rect(797, 76, 21), keyboardViewport, 256, 240)+ expect(style.top).toBe(793)+ expect(style.left).toBe(76)+ expect(style.transform).toBe("translateY(-100%)")+ })++ it("keeps the left margin when the visible viewport is narrower than the popup", () => {+ const narrowViewport = { top: 100, left: 50, width: 200, height: 300 }+ const style = anchoredPopoverStyle(rect(220, 200), narrowViewport, 256, 240)+ expect(style.left).toBe(58)+ expect(style.maxWidth).toBe(184)+ })+it("keeps zero-offset desktop geometry unchanged", () => {const style = anchoredPopoverStyle(rect(400, 40),diff --git a/src/web/src/hooks/use-anchored-popover.ts b/src/web/src/hooks/use-anchored-popover.tsindex 817d73bb6..3d6cce40d 100644--- a/src/web/src/hooks/use-anchored-popover.ts+++ b/src/web/src/hooks/use-anchored-popover.ts@@ -144,23 +144,20 @@ export function anchoredPopoverStyle(popupWidth: number,popupMaxHeight: number,): AnchoredPopoverStyle {- // `getBoundingClientRect()` / TipTap's `clientRect()` report coordinates in- // the visual viewport, while iOS lays out `position: fixed` descendants- // against the layout viewport. Convert only the final CSS coordinates back- // to layout space; all fit calculations stay in visual-viewport space.- const minVisibleLeft = VIEWPORT_MARGIN+ const viewportRight = viewport.left + viewport.width+ const viewportBottom = viewport.top + viewport.height+ const minVisibleLeft = viewport.left + VIEWPORT_MARGINconst maxVisibleLeft = Math.max(minVisibleLeft,- viewport.width - popupWidth - VIEWPORT_MARGIN,+ viewportRight - popupWidth - VIEWPORT_MARGIN,)- const visibleLeft = Math.min(+ const left = Math.min(Math.max(rect.left, minVisibleLeft),maxVisibleLeft,)- const left = viewport.left + visibleLeft- const spaceAbove = rect.top- const spaceBelow = viewport.height - rect.bottom+ const spaceAbove = rect.top - viewport.top+ const spaceBelow = viewportBottom - rect.bottomconst fullHeight = popupMaxHeight + POPOVER_CHROME_HEIGHT + POPOVER_GAP + VIEWPORT_MARGINconst placeBelow = spaceAbove < fullHeight&& (spaceBelow >= fullHeight || spaceBelow > spaceAbove)@@ -176,10 +173,10 @@ export function anchoredPopoverStyle(}return placeBelow- ? { ...common, top: viewport.top + rect.bottom + POPOVER_GAP }+ ? { ...common, top: rect.bottom + POPOVER_GAP }: {...common,- top: viewport.top + rect.top - POPOVER_GAP,+ top: rect.top - POPOVER_GAP,transform: "translateY(-100%)",}}diff --git a/src/web/src/test/e2e-ui/31-mention-candidate-pagination.spec.ts b/src/web/src/test/e2e-ui/31-mention-candidate-pagination.spec.tsindex ce90559ca..19a5cdced 100644--- a/src/web/src/test/e2e-ui/31-mention-candidate-pagination.spec.ts+++ b/src/web/src/test/e2e-ui/31-mention-candidate-pagination.spec.ts@@ -32,7 +32,35 @@ test("@ candidates page to completion, expose first search page, and keep statusconst serverId = await seedServer("alice", `Mention pages ${Date.now()}`)const channelId = await seedChannel("alice", serverId, "mention-pages")const { page } = await asUser("alice")- await page.setViewportSize({ width: 390, height: 640 })+ await page.setViewportSize({ width: 390, height: 844 })+ await page.addInitScript(() => {+ const geometry = {+ offsetTop: 0,+ offsetLeft: 0,+ width: 390,+ height: 844,+ }+ const viewport = new EventTarget()+ for (const property of ["offsetTop", "offsetLeft", "width", "height"] as const) {+ Object.defineProperty(viewport, property, {+ configurable: true,+ get: () => geometry[property],+ })+ }+ Object.defineProperty(viewport, "scale", { configurable: true, value: 1 })+ Object.defineProperty(window, "visualViewport", {+ configurable: true,+ value: viewport,+ })+ Object.defineProperty(window, "__setMentionTestVisualViewport", {+ configurable: true,+ value: (next: Partial<typeof geometry>) => {+ Object.assign(geometry, next)+ viewport.dispatchEvent(new Event("resize"))+ viewport.dispatchEvent(new Event("scroll"))+ },+ })+ })const browse = Array.from({ length: 12 }, (_, index) => candidate("Browse", index + 1))const matches = Array.from({ length: 205 }, (_, index) => candidate("CapMatch", index + 1))@@ -110,22 +138,54 @@ test("@ candidates page to completion, expose first search page, and keep statusawait expect(page.getByTestId(tid.mentionOption(matches[204]!.id))).toHaveCount(1)await expect(mentionOptions).toHaveCount(205)- const bounds = await page.getByTestId(tid.mentionPopup).evaluate((element) => {- const rect = element.getBoundingClientRect()+ const readBounds = () => page.getByTestId(tid.mentionPopup).evaluate((element) => {+ const popup = element.getBoundingClientRect()+ const selection = window.getSelection()+ if (!selection || selection.rangeCount === 0) throw new Error("Missing composer caret")+ const caret = selection.getRangeAt(0).getBoundingClientRect()const viewport = window.visualViewportreturn {- top: rect.top,- bottom: rect.bottom,- left: rect.left,- right: rect.right,- width: viewport?.width ?? window.innerWidth,- height: viewport?.height ?? window.innerHeight,+ popup: {+ top: popup.top,+ bottom: popup.bottom,+ left: popup.left,+ right: popup.right,+ },+ caret: { top: caret.top, bottom: caret.bottom },+ viewport: {+ top: viewport?.offsetTop ?? 0,+ bottom: (viewport?.offsetTop ?? 0) + (viewport?.height ?? window.innerHeight),+ left: viewport?.offsetLeft ?? 0,+ right: (viewport?.offsetLeft ?? 0) + (viewport?.width ?? window.innerWidth),+ },}})- expect(bounds.top).toBeGreaterThanOrEqual(0)- expect(bounds.left).toBeGreaterThanOrEqual(0)- expect(bounds.bottom).toBeLessThanOrEqual(bounds.height)- expect(bounds.right).toBeLessThanOrEqual(bounds.width)++ const expectAnchoredAbove = (bounds: Awaited<ReturnType<typeof readBounds>>) => {+ expect(bounds.caret.top).toBeGreaterThanOrEqual(bounds.viewport.top)+ expect(bounds.caret.bottom).toBeLessThanOrEqual(bounds.viewport.bottom)+ expect(bounds.popup.top).toBeGreaterThanOrEqual(bounds.viewport.top)+ expect(bounds.popup.bottom).toBeLessThanOrEqual(bounds.viewport.bottom)+ expect(bounds.popup.left).toBeGreaterThanOrEqual(bounds.viewport.left)+ expect(bounds.popup.right).toBeLessThanOrEqual(bounds.viewport.right)+ expect(bounds.popup.bottom - bounds.caret.top).toBeGreaterThanOrEqual(-5)+ expect(bounds.popup.bottom - bounds.caret.top).toBeLessThanOrEqual(-3)+ }++ expectAnchoredAbove(await readBounds())+ await page.evaluate(() => {+ const setViewport = Reflect.get(window, "__setMentionTestVisualViewport") as+ | ((geometry: { offsetTop: number; height: number }) => void)+ | undefined+ if (!setViewport) throw new Error("Missing controlled visual viewport")+ setViewport({ offsetTop: 364, height: 480 })+ })+ await page.evaluate(() => new Promise<void>((resolve) => {+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()))+ }))+ expectAnchoredAbove(await readBounds())+ await page.waitForTimeout(250)+ expectAnchoredAbove(await readBounds())await page.keyboard.press("Escape")await editable.press("ControlOrMeta+A")