graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Focus the composer after chat selection (#1171)
Rach Pradhan60672c58380b
diff --git a/apps/native/components/site/useNavigationPromptFocus.ts b/apps/native/components/site/useNavigationPromptFocus.tsindex f7291f96..98ec5ac9 100644--- a/apps/native/components/site/useNavigationPromptFocus.ts+++ b/apps/native/components/site/useNavigationPromptFocus.ts@@ -1,5 +1,6 @@import { useLayoutEffect, useRef, useState } from "react";import { focusNavigationPrompt } from "@/lib/navigation-prompt-focus";+import { flushSync } from "react-dom";/** Explicit navigation, not active-pane changes or draft renders, owns focus. */export function useNavigationPromptFocus() {@@ -13,5 +14,11 @@ export function useNavigationPromptFocus() {// Run once in the navigation commit, never retry later during typing.if (prompt) focusNavigationPrompt(prompt);}, [request]);- return { promptFocusRoot: root, requestPromptFocus: (id: number) => setRequest({ id }) };+ const requestPromptFocus = (id: number) => {+ const navigation = document.querySelector<HTMLElement>("[data-navigation-panel]:popover-open");+ if (!navigation) { setRequest({ id }); return; }+ navigation.addEventListener("toggle", () => flushSync(() => setRequest({ id })), { once: true });+ navigation.hidePopover();+ };+ return { promptFocusRoot: root, requestPromptFocus };}diff --git a/apps/native/electron/frontend-runtime.cjs b/apps/native/electron/frontend-runtime.cjsindex 96ebf3bd..aca06d50 100644--- a/apps/native/electron/frontend-runtime.cjs+++ b/apps/native/electron/frontend-runtime.cjs@@ -276,9 +276,10 @@ app.whenReady().then(async () => {report.passed.push('bounded split churn, resize, cancellation and memory checks');return;}- if (process.env.GRAFF_NARROW_NAV_TEST) await require('./narrow-navigation-frontend.cjs').runNarrowNavigation({ win, output, click, until, report });+ const narrowNavigation = Boolean(process.env.GRAFF_NARROW_NAV_TEST);+ if (narrowNavigation) await require('./narrow-navigation-frontend.cjs').runNarrowNavigation({ win, output, click, until, report });await require('./attachment-lifetime-frontend.cjs').runAttachments({win,origin,temp,output,requests,workspace,send,click,until,report});- if (process.env.GRAFF_NARROW_NAV_TEST) return;+ if (narrowNavigation) return;await require('./browser-focus-frontend.cjs').runBrowserFocus({ win, output, click, until, report });await require('./tab-drag-visual.cjs').runTabDrag({ win, origin, output });report.passed.push('trusted pointer and keyboard: tab reorder, horizontal/vertical splits, draft retention, Escape and four-pane limit');diff --git a/apps/native/electron/narrow-navigation-frontend.cjs b/apps/native/electron/narrow-navigation-frontend.cjsindex 6b6105ca..7ee47d66 100644--- a/apps/native/electron/narrow-navigation-frontend.cjs+++ b/apps/native/electron/narrow-navigation-frontend.cjs@@ -7,9 +7,25 @@ async function runNarrowNavigation({win, output, click, until, report}) {const escape = async () => {for (const type of ['keyDown','keyUp']) await desktop.testInput(wc, {type,keyCode:'Escape'});};+ const pointerClick = async selector => {+ await until(() => js(`!!document.querySelector(${JSON.stringify(selector)})`), 'pointer target mounts');+ const point = await js(`(()=>{const e=document.querySelector(${JSON.stringify(selector)}),r=e.getBoundingClientRect();return{x:r.x+r.width/2,y:r.y+r.height/2};})()`);+ for (const type of ['mouseDown','mouseUp']) await desktop.testInput(wc, {type,...point,button:'left',clickCount:1});+ };assert.equal(await js(`innerWidth < 1024`), true, 'Exercise the breakpoint that hid navigation');+ const first = await js(`document.querySelector('[data-chat][data-focused="true"]').dataset.chat`);+ const firstDraft = await js(`document.querySelector('[data-chat][data-focused="true"] textarea[aria-label="Prompt"]').value`);+ await click('[title="New chat (⌘T)"]');+ const second = await js(`document.querySelector('[data-chat][data-focused="true"]').dataset.chat`);+ assert.notEqual(second, first);await click('[aria-label="Open navigation"]');await until(() => js(`!!document.querySelector('[data-navigation-panel]:popover-open')`), 'navigation opens');+ await pointerClick(`[data-session-navigation="sidebar"] [data-tab-members="${first}"] button[aria-pressed]`);+ await desktop.testInput(wc, {type:'char',keyCode:'x'});+ await until(() => js(`!document.querySelector('[data-navigation-panel]:popover-open') && document.activeElement===document.querySelector('[data-chat="${first}"] textarea[aria-label="Prompt"]')`), 'chat selection dismisses navigation and focuses its prompt');+ assert.equal(await js(`document.querySelector('[data-chat="${first}"] textarea[aria-label="Prompt"]').value`), `${firstDraft}x`, 'the first character typed immediately after chat selection appends to its prompt');+ await click('[aria-label="Open navigation"]');+ await until(() => js(`!!document.querySelector('[data-navigation-panel]:popover-open')`), 'navigation reopens');await click('[data-workspace-trigger]');await until(() => js(`!!document.querySelector('[data-navigation-panel] [data-workspace-menu]')`), 'folder picker stays inside native popover layer');await escape();@@ -62,6 +78,7 @@ async function runNarrowNavigation({win, output, click, until, report}) {win.setContentSize(1320, 868);await until(() => js(`innerWidth >= 1024 && document.querySelector('[aria-label="Workspace navigation"]').getBoundingClientRect().width > 200 && !document.querySelector('[data-navigation-panel]').hasAttribute('popover')`), 'wide sidebar restored');assert.equal(await js(`document.querySelectorAll('[aria-label="Workspace navigation"]').length`), 1);+ report.passed.push('selecting a chat from narrow navigation closes the popover, focuses its prompt and sends typing there');report.passed.push('update controls stay unclipped and eight new chats cannot hide the navigation button');report.passed.push('narrow window: workspace picker and real saved-chat actions reachable; nested Escape, close control, outside dismissal and focus work; widening restores one sidebar');}diff --git a/apps/native/package.json b/apps/native/package.jsonindex 00292a8c..f0710632 100644--- a/apps/native/package.json+++ b/apps/native/package.json@@ -53,7 +53,7 @@"install:cli": "bun scripts/install-cli.mjs","test:packaged-html": "bun scripts/test-packaged-html.mjs","test:workspace-history": "GRAFF_WORKSPACE_HISTORY_TEST=1 bun scripts/test-frontend.mjs",- "test:narrow-navigation": "GRAFF_NARROW_NAV_TEST=1 bun scripts/test-frontend.mjs",+ "test:narrow-navigation": "GRAFF_NARROW_NAV_TEST=chat-prompt-focus bun scripts/test-frontend.mjs","test:packaged-titles": "bun scripts/test-packaged-titles.mjs","test:clipboard-narrow": "GRAFF_FRONTEND_NARROW=1 bun scripts/test-frontend.mjs","test:context-meter": "GRAFF_CONTEXT_METER_TEST=1 bun scripts/test-frontend.mjs"