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(ui): keep the # and @ picker on screen when typed near the right edge (#3132)

Call Whiteda8105f37637
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 081ecc567..bf2aa2e81 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -236,6 +236,8 @@ jobs:
npm run test:voice-shortcut
npm run test:chat-selection
npm run test:badge-triggers
+ # Against the built app: StrictMode's dev double-mount drops the picker's first open.
+ npm run test:workbench-general-build -- composer-mention-picker.spec.ts
- lane: 2
suites: |
npm run test:project-order
diff --git a/ui/e2e/workbench-general/composer-mention-picker.spec.ts b/ui/e2e/workbench-general/composer-mention-picker.spec.ts
new file mode 100644
index 000000000..151ae1574
--- /dev/null
+++ b/ui/e2e/workbench-general/composer-mention-picker.spec.ts
@@ -0,0 +1,109 @@
+import { expect, test, type Page } from '@playwright/test';
+import { open, serveProduct } from './support';
+
+// The `#` and `@` pickers open at the caret. Typed near the composer's right
+// edge on a phone, the list must still open whole on screen: shifted left as
+// far as it needs, never past either edge, and still above the caret.
+
+const SESSION_ID = 'mention-picker-fixture';
+const MARGIN = 8;
+
+async function serveChat(page: Page) {
+ const denied = await serveProduct(page);
+ const session = {
+ id: SESSION_ID, scope_id: 'fixture', project_id: 'proj-1', title: 'Mention picker',
+ agent_id: 'agt-pm', agent_name: 'pm-claude', agent_backend: 'claude', model: 'claude-opus-4-7',
+ reasoning_effort: null, speed: null, status: 'active', agent_status: 'idle', pinned: false,
+ workdir: '/fixture/work', native_session_id: 'native-1', metadata: {},
+ created_at: '2026-11-01T00:00:00Z', updated_at: '2026-11-01T00:00:00Z',
+ };
+ const turnState = {
+ in_flight: false, foreground: 'idle', native_turn_started: false,
+ pending_input_count: 0, background_activities: [], pending_activity_output_count: 0, connection: 'connected',
+ };
+ const agents = [
+ { id: 'agt-pm', name: 'pm-claude', backend: 'claude', enabled: true, model: 'claude-opus-4-7' },
+ { id: 'agt-research', name: 'research-assistant-with-a-long-name', backend: 'codex', enabled: true, model: 'gpt-6-astra' },
+ { id: 'agt-ops', name: 'ops', backend: 'vibey', enabled: true, model: 'claude-sonnet-5-5' },
+ ];
+ // Long titles: the list is as wide as it gets, not only its minimum.
+ const others = [
+ 'Review the release checklist before the Friday cut',
+ 'Reproduce the Windows first-run bootstrap failure on a clean VM',
+ 'Benchmark relay latency',
+ 'PR watch for the usage ledger',
+ ].map((title, index) => ({ ...session, id: `other-${index}`, title }));
+ await page.route(`**/api/sessions/${SESSION_ID}/bootstrap`, (route) => route.fulfill({ json: {
+ session, capabilities: { can_chat: true }, agents, default_agent_name: 'pm-claude', config: { ui: {} },
+ messages: [], queued: [], next_after_id: null, next_before_id: null,
+ draft: { text: '', updated_at: null }, turn_state: turnState,
+ } }));
+ await page.route((url) => url.pathname === '/api/sessions', (route) => route.fulfill({ json: { sessions: [session, ...others] } }));
+ await page.route(`**/api/sessions/${SESSION_ID}`, (route) => route.fulfill({ json: session }));
+ await page.route(`**/api/sessions/${SESSION_ID}/queue`, (route) => route.fulfill({ json: [] }));
+ // Typing saves the draft; answered here so the guard records no write.
+ await page.route(`**/api/sessions/${SESSION_ID}/draft`, (route) => route.fulfill({ json: { ok: true } }));
+ await page.route(`**/api/sessions/${SESSION_ID}/turn-state`, (route) => route.fulfill({ json: turnState }));
+ await page.route(`**/api/sessions/${SESSION_ID}/activity**`, (route) => route.fulfill({ json: { groups: [] } }));
+ await page.route(`**/api/inbox/${SESSION_ID}/read`, (route) => route.fulfill({ json: { ok: true } }));
+ await page.route('**/api/asr/status', (route) => route.fulfill({ json: { available: false } }));
+ await page.route('**/api/models/agents/**', (route) => route.fulfill({ json: { ok: false } }));
+ await page.route('**/api/workbench/prefs', (route) => route.fulfill({ json: {
+ ok: true, background_work_banner_enabled: true, fast_mode_default: false,
+ } }));
+ return denied;
+}
+
+async function typeToTheRightEdge(page: Page) {
+ const editor = page.locator('main [contenteditable="true"]').last();
+ await editor.click();
+ // Grow the first line until the caret sits within a few characters of the edge.
+ const box = (await editor.boundingBox())!;
+ for (let i = 0; i < 80; i += 1) {
+ await page.keyboard.type('m');
+ const caretX = await page.evaluate(() => {
+ const range = window.getSelection()!.getRangeAt(0).cloneRange();
+ return range.getBoundingClientRect().right;
+ });
+ if (caretX > box.x + box.width - 24) break;
+ }
+ await page.keyboard.type(' ');
+}
+
+for (const { trigger, width } of [
+ { trigger: '#', width: 390 },
+ { trigger: '#', width: 320 },
+ { trigger: '@', width: 390 },
+]) {
+ test(`the ${trigger} picker opens whole on a ${width}px phone when typed at the right edge`, async ({ page }) => {
+ const denied = await serveChat(page);
+ await page.setViewportSize({ width, height: 760 });
+ await open(page, `/chat/${SESSION_ID}`);
+ await typeToTheRightEdge(page);
+ await page.keyboard.type(trigger);
+
+ const picker = page.locator('[data-mention-picker]');
+ await expect(picker.locator('li').first()).toBeVisible();
+ // Results arrive after the list opens; read the settled place.
+ const span = async () => {
+ const box = (await picker.boundingBox())!;
+ return [Math.round(box.x), Math.round(box.x + box.width)];
+ };
+ await expect.poll(async () => {
+ const [left, right] = await span();
+ return left >= MARGIN - 1 && right <= width - MARGIN + 1;
+ }, { message: `picker spans ${JSON.stringify(await span())} of a ${width}px screen` }).toBe(true);
+ // Still opens above the caret, clear of the line being typed.
+ const caret = await page.evaluate(() => {
+ const rect = window.getSelection()!.getRangeAt(0).getBoundingClientRect();
+ return rect.top + rect.height / 2;
+ });
+ const pickerBox = (await picker.boundingBox())!;
+ expect(pickerBox.y + pickerBox.height).toBeLessThan(caret);
+ await page.screenshot({ path: `e2e/.artifacts/workbench-general/shots/composer-mention-picker-${trigger === '#' ? 'session' : 'agent'}-${width}.png` });
+
+ await page.keyboard.press('Escape');
+ await expect(picker).toHaveCount(0);
+ expect(denied).toEqual([]);
+ });
+}
diff --git a/ui/playwright.workbench-general-build.config.ts b/ui/playwright.workbench-general-build.config.ts
index 38f1cbf58..55e5e8192 100644
--- a/ui/playwright.workbench-general-build.config.ts
+++ b/ui/playwright.workbench-general-build.config.ts
@@ -19,13 +19,19 @@ import { defineConfig, devices } from '@playwright/test';
* so the spec runs against the bundle users actually get rather than working
* around it here or changing that component.
*
+ * `composer-mention-picker.spec.ts` is here for the same StrictMode reason: on the
+ * dev server the `#`/`@` typeahead's first open in a freshly mounted editor
+ * often never renders its list, so a spec about where that list lands would
+ * grade the development double-mount rather than the picker. The built app
+ * opens it every time.
+ *
* The build runs as part of the server command so the spec can never grade a
* stale `dist/`. Port and origin match the dev config because the spec's request
* guard is written against that one origin.
*/
export default defineConfig({
testDir: './e2e/workbench-general',
- testMatch: ['**/mobile-continuation.spec.ts', '**/setup-handoff.spec.ts'],
+ testMatch: ['**/mobile-continuation.spec.ts', '**/setup-handoff.spec.ts', '**/composer-mention-picker.spec.ts'],
outputDir: './e2e/.artifacts/workbench-general/run',
workers: 1,
retries: 0,
diff --git a/ui/playwright.workbench-general.config.ts b/ui/playwright.workbench-general.config.ts
index 51589bf85..29caeae9f 100644
--- a/ui/playwright.workbench-general.config.ts
+++ b/ui/playwright.workbench-general.config.ts
@@ -6,7 +6,7 @@ import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './e2e/workbench-general',
// Run against the built app instead — see playwright.workbench-general-build.config.ts.
- testIgnore: ['**/mobile-continuation.spec.ts', '**/setup-handoff.spec.ts'],
+ testIgnore: ['**/mobile-continuation.spec.ts', '**/setup-handoff.spec.ts', '**/composer-mention-picker.spec.ts'],
// Playwright empties `outputDir` at the start of every run, including a filtered
// one, so the captures must NOT live inside it: a `-g` re-run of two shots would
// otherwise delete the other sixteen. Traces get their own subdirectory and the
diff --git a/ui/src/components/workbench/MentionEditor.tsx b/ui/src/components/workbench/MentionEditor.tsx
index 0d7e25194..9451d1bcc 100644
--- a/ui/src/components/workbench/MentionEditor.tsx
+++ b/ui/src/components/workbench/MentionEditor.tsx
@@ -782,8 +782,61 @@ function MultilineInsertFixPlugin() {
return null;
}
+// The list's least distance from either screen edge, and the cap on its width.
+const MENU_EDGE_GAP = 8;
+
+/**
+ * Keeps the picker whole on screen horizontally. It opens at the caret, so typed
+ * near the right edge of a phone it would run off the screen: shift it left as
+ * far as it needs, never past the left edge. Lexical's own clamp measures the
+ * menu once, before its results render, and not again as the caret moves, so it
+ * cannot do this. The shift is recomputed whenever the list resizes (results
+ * arrive), its anchor moves (the caret), or the viewport changes, and is derived
+ * from the unshifted position each time, so it never compounds. Horizontal only:
+ * see MentionMenu for why the vertical side is not measured.
+ */
+function useWithinViewport(ref: React.RefObject<HTMLElement | null>) {
+ useLayoutEffect(() => {
+ const element = ref.current;
+ if (!element) return undefined;
+ let shift = 0;
+ const place = () => {
+ const rect = element.getBoundingClientRect();
+ const viewport = window.visualViewport;
+ const minLeft = (viewport?.offsetLeft ?? 0) + MENU_EDGE_GAP;
+ const maxRight = (viewport ? viewport.offsetLeft + viewport.width : document.documentElement.clientWidth) - MENU_EDGE_GAP;
+ const left = rect.left - shift;
+ const right = rect.right - shift;
+ let next = right > maxRight ? maxRight - right : 0;
+ if (left + next < minLeft) next = minLeft - left;
+ if (Math.abs(next - shift) < 0.5) return;
+ shift = next;
+ element.style.translate = shift ? `${shift}px 0` : '';
+ };
+ place();
+ const resized = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(place);
+ resized?.observe(element);
+ // The anchor is the element Lexical moves to the caret on every keystroke.
+ const moved = element.parentElement && typeof MutationObserver !== 'undefined'
+ ? new MutationObserver(place)
+ : null;
+ if (moved && element.parentElement) moved.observe(element.parentElement, { attributes: true, attributeFilter: ['style'] });
+ window.addEventListener('resize', place);
+ window.visualViewport?.addEventListener('resize', place);
+ return () => {
+ resized?.disconnect();
+ moved?.disconnect();
+ window.removeEventListener('resize', place);
+ window.visualViewport?.removeEventListener('resize', place);
+ };
+ }, [ref]);
+}
+
const MentionMenu = forwardRef<HTMLUListElement, BeautifulMentionsMenuProps>(
- ({ loading: _loading, children, ...props }, ref) => (
+ ({ loading: _loading, children, ...props }, forwardedRef) => {
+ const ref = useRef<HTMLUListElement | null>(null);
+ useWithinViewport(ref);
+ return (
// Always open ABOVE the caret as an out-of-flow overlay — the chat composer is
// pinned to the viewport bottom. Pinning the BOTTOM edge to the anchor (caret)
// means the list grows UPWARD as async results load, with no reposition or
@@ -794,14 +847,20 @@ const MentionMenu = forwardRef<HTMLUListElement, BeautifulMentionsMenuProps>(
// timing). The plugin's own flip needs a 1–2 item list AND a tall multiline
// composer to trigger, which our 5–8 item menus effectively never hit.
<ul
- ref={ref}
+ ref={(node) => {
+ ref.current = node;
+ if (typeof forwardedRef === 'function') forwardedRef(node);
+ else if (forwardedRef) forwardedRef.current = node;
+ }}
data-mention-picker
- className="absolute left-0 z-50 mb-4 !bottom-full !top-auto max-h-64 min-w-[15rem] list-none overflow-y-auto overflow-x-hidden rounded-md border border-border bg-panel p-1 text-text shadow-md"
+ // Never wider than the screen less its gaps, so the shift above can always fit it.
+ className="absolute left-0 z-50 mb-4 !bottom-full !top-auto max-h-64 min-w-[min(15rem,calc(100vw-1rem))] max-w-[calc(100vw-1rem)] list-none overflow-y-auto overflow-x-hidden rounded-md border border-border bg-panel p-1 text-text shadow-md"
{...props}
>
{children}
</ul>
- ),
+ );
+ },
);
MentionMenu.displayName = 'MentionMenu';