diff --git a/tests/e2e/classic-workspace.spec.ts b/tests/e2e/classic-workspace.spec.ts index f672f69af75..7c56e70f0a7 100644 --- a/tests/e2e/classic-workspace.spec.ts +++ b/tests/e2e/classic-workspace.spec.ts @@ -1,6 +1,55 @@ import { expect, test } from "@playwright/test"; import { json, setup } from "./agent-chat.shared"; +test("expanding an already visible plan briefly highlights it and preserves keyboard focus", async ({ page, request }) => { + const company = await json(await request.post("/api/companies", { data: { name: "Plan focus" } })); + const preference = await json(await request.get("/api/workspace-preferences/me")); + const preferenceUrl = `/api/companies/${company.id}/workspace-preferences/me`; + try { + await json(await request.put(preferenceUrl, { data: { coordinatorWorkspaceEnabled: false } })); + const issue = await json(await request.post(`/api/companies/${company.id}/issues`, { + data: { title: "Review the launch", status: "backlog" }, + })); + await json(await request.put(`/api/issues/${issue.id}/documents/plan`, { + data: { title: "Launch plan", body: "# Launch plan\n\nReview the checklist.", format: "markdown" }, + })); + await json(await request.put(`/api/issues/${issue.id}/documents/notes`, { + data: { title: "Launch notes", body: "Record the decisions.", format: "markdown" }, + })); + await page.setViewportSize({ width: 1440, height: 900 }); + const taskUrl = `/${company.issuePrefix}/issues/${issue.identifier}`; + await page.goto(taskUrl); + const card = page.getByRole("link", { name: "Open Plan revision 1", exact: true }); + const pane = page.getByRole("tabpanel", { name: "Launch plan", exact: true }); + await expect(pane.getByText("Review the checklist.")).toBeVisible(); + await card.click(); + await expect(pane).toBeFocused(); + await page.getByRole("tab", { name: "Properties", exact: true }).click(); + await card.click(); + await expect(pane.getByText("Review the checklist.")).toBeVisible(); + await expect(pane).not.toBeFocused(); + await card.click(); + await expect(pane).toBeFocused(); + await expect(pane).toHaveCSS("animation-name", "plan-pane-attention"); + await pane.evaluate(el => Promise.all(el.getAnimations().map(animation => animation.finished)).then(() => undefined)); + await expect(pane).toHaveCSS("outline-color", /(?:, 0| \/ 0)\)$/); + await expect(pane).toBeFocused(); + await card.press("Enter"); + await expect(pane).toBeFocused(); + await page.keyboard.press("Tab"); + await expect(pane.getByRole("button", { name: "Open comments on plan" })).toBeFocused(); + await card.press("Enter"); + await expect(pane).toBeFocused(); + await page.goto(`${taskUrl}#document-notes`); + const notes = page.getByRole("tabpanel", { name: "Launch notes", exact: true }); + await expect(notes.getByText("Record the decisions.")).toBeVisible(); + await expect(notes).not.toBeFocused(); + } finally { + await json(await request.put(preferenceUrl, { data: { coordinatorWorkspaceEnabled: preference.coordinatorWorkspaceEnabled } })); + await request.delete(`/api/companies/${company.id}`); + } +}); + test("Coordinator is standard and Classic is an explicit personal experiment", async ({ page, request }) => { const original = await json(await request.get("/api/workspace-preferences/me")); const f = await setup(request); diff --git a/ui/src/components/task-chat/TaskChatPlanPreviewCard.tsx b/ui/src/components/task-chat/TaskChatPlanPreviewCard.tsx index fe54d7a2590..379beedfc4c 100644 --- a/ui/src/components/task-chat/TaskChatPlanPreviewCard.tsx +++ b/ui/src/components/task-chat/TaskChatPlanPreviewCard.tsx @@ -176,6 +176,7 @@ export function TaskChatPlanPreviewCard({ return ( void; checkingMonitorNow?: boolean; fileTabsEnabled: boolean; - documentDeepLink?: { requestId: number; documentKey: string } | null; + documentDeepLink?: { requestId: number; documentKey: string; focusActivePlan?: boolean } | null; showDocumentSourceTask?: boolean; onArtifactVisibilityChange?: (showsArtifact: boolean) => void; /** A new durable output asks the host to reveal this tab once. */ @@ -503,8 +504,10 @@ function TaskSidePanelForScope({ // A refresh must not replay a link after the user selects another tab. handledDocumentRequestRef.current = documentDeepLink.requestId; if (coordinatorWorkspaceEnabled) userInteractedRef.current = true; - controller.openTab(taskPanelDocumentTab(documentDeepLink.documentKey, label, target?.revisionId, documentIssueId)); - }, [controller.openTab, documentDeepLink, documents, planDocument, location.hash, issue.id]); + const tab = taskPanelDocumentTab(documentDeepLink.documentKey, label, target?.revisionId, documentIssueId); + if (documentDeepLink.focusActivePlan && documentDeepLink.documentKey === "plan" && tab.id === controller.activeTabId) focusPlanPane(bodyRef.current); + controller.openTab(tab); + }, [controller.activeTabId, controller.openTab, documentDeepLink, documents, planDocument, location.hash, issue.id]); // Existing URL-backed workspace links remain the external integration API. useEffect(() => { @@ -594,11 +597,10 @@ function TaskSidePanelForScope({ } } - useEffect(() => { - const top = controller.activeTabId ? scrollPositionsRef.current.get(controller.activeTabId) ?? 0 : 0; - window.requestAnimationFrame(() => bodyRef.current?.scrollTo({ top, behavior: "auto" })); + useLayoutEffect(() => { + const top = scrollPositionsRef.current.get(controller.activeTabId ?? "") ?? 0; + return scheduleTaskPaneScroll(bodyRef.current, top); }, [controller.activeTabId]); - useEffect(() => { if (activeTab) return; window.requestAnimationFrame(() => { diff --git a/ui/src/components/task-side-panel/task-pane-focus.ts b/ui/src/components/task-side-panel/task-pane-focus.ts new file mode 100644 index 00000000000..c5c4a7c187c --- /dev/null +++ b/ui/src/components/task-side-panel/task-pane-focus.ts @@ -0,0 +1,36 @@ +export function focusPlanPane(pane: HTMLElement | null) { + if (!pane) return; + + pane.tabIndex = -1; + pane.focus({ preventScroll: true }); + if (pane.ownerDocument.activeElement !== pane) { + pane.removeAttribute("tabindex"); + return; + } + + if (!pane.hasAttribute("data-plan-pane-attention")) { + pane.setAttribute("data-plan-pane-attention", ""); + pane.addEventListener("blur", () => { + pane.removeAttribute("data-plan-pane-attention"); + pane.removeAttribute("tabindex"); + }, { once: true }); + return; + } + + const cue = pane.getAnimations().find(animation => + animation instanceof CSSAnimation && animation.animationName === "plan-pane-attention"); + if (cue) { + cue.currentTime = 0; + cue.play(); + } +} + +export function scheduleTaskPaneScroll(pane: HTMLElement | null, top: number) { + if (!pane) return; + + const frame = requestAnimationFrame(() => pane.scrollTo({ top, behavior: "auto" })); + return () => { + cancelAnimationFrame(frame); + if (pane.hasAttribute("data-plan-pane-attention")) pane.blur(); + }; +} diff --git a/ui/src/index.css b/ui/src/index.css index c732cca63af..ce35ec4a283 100644 --- a/ui/src/index.css +++ b/ui/src/index.css @@ -476,6 +476,7 @@ --motion-ease-scroll-pill-in: cubic-bezier(0.23, 1, 0.32, 1); --motion-ease-scroll-pill-out: cubic-bezier(0.7, 0, 0.84, 0); --motion-pane-glide: 320ms; /* properties-pane maximize/restore glide */ + --plan-pane-attention-duration: 520ms; --motion-pane-reveal: var(--motion-duration-slow); --motion-ease-pane-reveal: var(--motion-ease-out-expo); --motion-pane-width-reset: 200ms; @@ -1487,6 +1488,22 @@ html:has(.paperclip-app-shell[data-keyboard-open="true"] [data-classic-task-shel /* Properties-pane maximize/restore glide (left animates between docked and sidebar-flush while the pane is position:fixed). */ .tc-pane-glide { transition: left var(--motion-pane-glide) var(--motion-ease-standard); } +[data-plan-pane-attention]:focus { + outline: var(--sz-2px) solid transparent; + outline-offset: calc(-1 * var(--sz-2px)); + animation: plan-pane-attention var(--plan-pane-attention-duration) var(--motion-ease-standard) both; +} +@keyframes plan-pane-attention { + from { outline-color: var(--plan-pane-attention-start, transparent); } + 25% { outline-color: var(--ring); } + to { outline-color: transparent; } +} +@media (prefers-reduced-motion: reduce) { + [data-plan-pane-attention]:focus { + --plan-pane-attention-start: var(--ring); + animation-timing-function: steps(1, end); + } +} .properties-panel-docked { transition: width var(--motion-pane-reveal) var(--motion-ease-pane-reveal), opacity var(--motion-pane-reveal) var(--motion-ease-pane-reveal); diff --git a/ui/src/pages/IssueDetail.tsx b/ui/src/pages/IssueDetail.tsx index 106e72716f0..c727d0857be 100644 --- a/ui/src/pages/IssueDetail.tsx +++ b/ui/src/pages/IssueDetail.tsx @@ -3331,7 +3331,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS setOpenSkill((current) => current?.id === skillId ? null : current); }, []); const [documentDeepLink, setDocumentDeepLink] = useState< - (IssuePropertiesDocumentDeepLink & { issueId: string }) | null + (IssuePropertiesDocumentDeepLink & { issueId: string; focusActivePlan?: boolean }) | null >(null); const [fileViewerPromptOpen, setFileViewerPromptOpen] = useState(false); const [detailTab, setDetailTab] = useState("chat"); @@ -6648,8 +6648,9 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS // the issue param so navigating to another issue with an identical hash // still maximizes the destination pane. const lastMaximizeRequestKeyRef = useRef(null); + const planExpandNavigation = useRef<{ pathname: string; hash: string } | null>(null); const routeIssueDocumentDeepLink = useCallback( - (hash: string) => { + (hash: string, focusActivePlan = false) => { const resolvedRoute = resolveIssueDocumentDeepLink(hash); // A handoff is a saved document too. Opening it must not switch the // conversation to full activity just because it has a legacy hash. @@ -6692,6 +6693,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS issueId: targetIssueId, tab: route.tab, documentKey: route.documentKey, + focusActivePlan, requestId: current?.issueId === targetIssueId ? current.requestId + 1 : 1, })); @@ -6710,7 +6712,9 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS ); useEffect(() => { - if (!routeIssueDocumentDeepLink(location.hash)) { + const expand = planExpandNavigation.current; + planExpandNavigation.current = null; + if (!routeIssueDocumentDeepLink(location.hash, expand?.pathname === location.pathname && expand.hash === location.hash)) { setDocumentDeepLink(null); // The deep link ended (hash cleared or issue changed): drop any // maximize request the panel never consumed so it cannot maximize a @@ -6721,6 +6725,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS }, [ issueId, location.hash, + location.pathname, routeIssueDocumentDeepLink, clearPanelMaximizeRequest, ]); @@ -6764,9 +6769,11 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS event.preventDefault(); // Let link handlers close any hovered task preview. Router links and // popover triggers honor defaultPrevented and skip their navigation. + const focusActivePlan = anchor.hasAttribute("data-plan-expand") && !isMobile && panelVisible && !suppressPanelUntilPlan; if (hash === location.hash) { - routeIssueDocumentDeepLink(hash); + routeIssueDocumentDeepLink(hash, focusActivePlan); } else { + planExpandNavigation.current = focusActivePlan ? { pathname: location.pathname, hash } : null; navigate(`${location.pathname}${location.search}${hash}`, { preventScrollReset: true, state: { @@ -6785,6 +6792,9 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS issue?.identifier, issueId, persistedAgentChat, + isMobile, + panelVisible, + suppressPanelUntilPlan, navigate, location.hash, location.key,