Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(chat): keep the mobile selection toolbar beside one-line mixed-font selections (#2808)

Call White33a2da6bb40b
diff --git a/docs/plans/mobile-selection-toolbar-ios27.md b/docs/plans/mobile-selection-toolbar-ios27.md
index 6575d7dde..21ab1f8d1 100644
--- a/docs/plans/mobile-selection-toolbar-ios27.md
+++ b/docs/plans/mobile-selection-toolbar-ios27.md
@@ -18,7 +18,10 @@ pointer ownership that is released only by those terminal events, so a withheld
- Clearing or changing the selection must hide or recompute the toolbar even if
a previous touch ended without a terminal event.
- On coarse pointers, the toolbar is placed at least 44px plus the existing
- 8px gap from the first or last selection line used as its anchor.
+ 8px gap from both endpoint selection lines.
+- A one-line selection whose endpoint rects differ by sub-pixel amounts (for
+ example, bold text followed by regular text) still sits directly above or
+ below its line, never at a viewport edge.
- Quote, Ask in a new session, and Copy still activate once on a complete
pointer gesture; keyboard activation remains unchanged.
- Desktop placement and selection behavior remain unchanged except for using
@@ -34,11 +37,13 @@ pointer ownership that is released only by those terminal events, so a withheld
when the bounded 700ms grace period expires.
- Track the first and last client rects of the selection instead of only the
aggregate range rect.
-- Place the touch toolbar above the first line or below the last line with a
- 52px safe offset. Evaluate those positions, the safe middle band, and the
- viewport edges as full-rectangle candidates; choose a candidate that does
- not intersect either expanded endpoint handle region, or the candidate with
- the smallest overlap when no fully safe slot exists.
+- Place the touch toolbar above the topmost or below the bottommost endpoint
+ line with a 52px safe offset, so neither slot can overlap the other
+ endpoint's handle region when both endpoints share a line. Evaluate those
+ positions, the safe middle band, and the viewport edges as full-rectangle
+ candidates; choose a candidate that does not intersect either expanded
+ endpoint handle region, or the candidate with the smallest overlap when no
+ fully safe slot exists.
## Select-all touch completion
@@ -55,7 +60,8 @@ physical-device limits are documented in
- Component tests simulate pointerdown without any terminal pointer event,
clear the selection, select new text, and activate the new toolbar.
-- Geometry tests verify the toolbar clears the native 44px handle region.
+- Geometry tests verify the toolbar clears the native 44px handle region,
+ including a one-line selection with WebKit-measured mixed-font endpoint rects.
- Long-selection geometry tests cover endpoint lines near or beyond both
viewport edges and the safe middle band between visible endpoints.
- Focused UI tests, changed-file lint, and production build are required.
diff --git a/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx b/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
index 7bb4e1819..61572e1a0 100644
--- a/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
+++ b/ui/src/components/workbench/SelectionQuoteToolbar.test.tsx
@@ -565,6 +565,40 @@ describe('chat selection action gesture lifetime', () => {
}
});
+ // Rects WebKit reports for a one-line selection that starts in bold text
+ // ("**v6**:…"): the bold rect sits a fraction of a pixel lower than the
+ // regular-text rect after it. Offsets place the line in each viewport half.
+ it.each([
+ ['below', 0],
+ ['above', -258],
+ ] as const)('places a one-line mixed-font selection %s its line, not at the viewport edge', (side, shift) => {
+ const first = { top: 458.060546875 + shift, bottom: 474.548828125 + shift, left: 50.59375, right: 67.95361328125 };
+ const last = { top: 458.046875 + shift, bottom: 474.53125 + shift, left: 67.59375, right: 259.59375 };
+ selectionLineRects = [first, last].map((rect) => ({
+ ...rect,
+ width: rect.right - rect.left,
+ height: rect.bottom - rect.top,
+ }));
+ selectionBounds = {
+ top: last.top,
+ bottom: first.bottom,
+ left: first.left,
+ right: last.right,
+ width: last.right - first.left,
+ height: first.bottom - last.top,
+ };
+ mountToolbar();
+ const toolbar = screen.getByRole('toolbar');
+ const top = Number.parseFloat(toolbar.getAttribute('style')!.match(/top:\s*([^;]+)/)![1]);
+
+ expect(top).toBeCloseTo(
+ side === 'below' ? first.bottom + 44 + 8 : last.top - 36 - 44 - 8,
+ );
+ for (const line of selectionLineRects) {
+ expect(top >= line.bottom + 44 + 8 || top + 36 <= line.top - 44 - 8).toBe(true);
+ }
+ });
+
it('keeps desktop placement at the original selection gap', () => {
coarsePointer = false;
selectionBounds = { ...defaultBounds, top: 80, bottom: 116 };
diff --git a/ui/src/components/workbench/SelectionQuoteToolbar.tsx b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
index d3f60aa6f..8cd57a0c4 100644
--- a/ui/src/components/workbench/SelectionQuoteToolbar.tsx
+++ b/ui/src/components/workbench/SelectionQuoteToolbar.tsx
@@ -326,8 +326,14 @@ export const SelectionQuoteToolbar: React.FC<{
const bottomEdge = Math.max(EDGE, window.innerHeight - toolbarHeight - EDGE);
const clampTop = (rawTop: number) => Math.min(Math.max(rawTop, topEdge), bottomEdge);
const preferBelow = (sel.top + sel.bottom) / 2 >= window.innerHeight / 2;
- const preferredAboveTop = clampTop(sel.first.top - toolbarHeight - placementGap);
- const preferredBelowTop = clampTop(sel.last.bottom + placementGap);
+ // Anchor above/below the vertical extent of BOTH endpoint lines. On a single
+ // line, the first and last rects can differ by a fraction of a pixel (bold vs
+ // regular text); anchoring on one alone left each slot overlapping the other
+ // endpoint's handle region, dropping the toolbar to the viewport edge.
+ const anchorTop = Math.min(sel.first.top, sel.last.top);
+ const anchorBottom = Math.max(sel.first.bottom, sel.last.bottom);
+ const preferredAboveTop = clampTop(anchorTop - toolbarHeight - placementGap);
+ const preferredBelowTop = clampTop(anchorBottom + placementGap);
// Clamp by the on-screen (capped) width so a toolbar wider than the viewport
// centers + scrolls internally instead of pushing an edge off-screen.
const leftHalf = Math.min(width, window.innerWidth - 2 * EDGE) / 2;
@@ -339,7 +345,7 @@ export const SelectionQuoteToolbar: React.FC<{
let top: number;
if (!isTouch) {
// Desktop has no OS selection menu — just prefer above, flip if no room.
- top = sel.first.top >= toolbarHeight + GAP + EDGE
+ top = anchorTop >= toolbarHeight + GAP + EDGE
? preferredAboveTop
: preferredBelowTop;
} else {