diff --git a/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.tsx b/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.tsx index a45fb1014..19e2696b6 100644 --- a/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.tsx +++ b/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.tsx @@ -194,11 +194,10 @@ export default function SmartWorkspaceNameField({ const [linearLoading, setLinearLoading] = useState(false) const [commandValue, setCommandValue] = useState('') const localInputRef = useRef(null) - const selectedSourceRef = useRef(null) + const focusedSelectedSourceKeyRef = useRef(null) const tabsListRef = useRef(null) const repoSlugCacheRef = useRef>(new Map()) const handledCrossRepoUrlRef = useRef(null) - const selectedSourceFocusFrameRef = useRef(null) const localInputFocusFrameRef = useRef(null) const [crossRepoPrompt, setCrossRepoPrompt] = useState<{ link: NonNullable> @@ -240,14 +239,28 @@ export default function SmartWorkspaceNameField({ }, [inputRef] ) - - const cancelSelectedSourceFocusFrame = useCallback((): void => { - if (selectedSourceFocusFrameRef.current === null) { - return - } - cancelAnimationFrame(selectedSourceFocusFrameRef.current) - selectedSourceFocusFrameRef.current = null - }, []) + const selectedSourceFocusKey = selectedSource + ? `${selectedSource.kind}:${selectedSource.label}:${selectedSource.url ?? ''}` + : null + const setSelectedSourceNode = useCallback( + (node: HTMLDivElement | null) => { + if (!node) { + focusedSelectedSourceKeyRef.current = null + return + } + if ( + !selectedSourceFocusKey || + focusedSelectedSourceKeyRef.current === selectedSourceFocusKey + ) { + return + } + focusedSelectedSourceKeyRef.current = selectedSourceFocusKey + // Why: after Enter accepts a source row, the input unmounts. Move focus + // to the pill immediately so the next Enter advances to Agent. + node.focus({ preventScroll: true }) + }, + [selectedSourceFocusKey] + ) const cancelLocalInputFocusFrame = useCallback((): void => { if (localInputFocusFrameRef.current === null) { @@ -257,13 +270,7 @@ export default function SmartWorkspaceNameField({ localInputFocusFrameRef.current = null }, []) - useEffect( - () => () => { - cancelSelectedSourceFocusFrame() - cancelLocalInputFocusFrame() - }, - [cancelLocalInputFocusFrame, cancelSelectedSourceFocusFrame] - ) + useEffect(() => cancelLocalInputFocusFrame, [cancelLocalInputFocusFrame]) useEffect(() => { if (disabled || textOnly) { @@ -329,20 +336,6 @@ export default function SmartWorkspaceNameField({ return () => window.clearTimeout(timer) }, [value]) - useEffect(() => { - if (selectedSource) { - setOpen(false) - // Why: after Enter accepts a PR/issue row, the input unmounts. Keep the - // keyboard flow on the source field so the next Enter advances to Agent. - cancelSelectedSourceFocusFrame() - selectedSourceFocusFrameRef.current = requestAnimationFrame(() => { - selectedSourceFocusFrameRef.current = null - selectedSourceRef.current?.focus({ preventScroll: true }) - }) - } - return cancelSelectedSourceFocusFrame - }, [cancelSelectedSourceFocusFrame, selectedSource]) - const normalizedGhQuery = useMemo( () => normalizeGitHubLinkQuery(debouncedQuery), [debouncedQuery] @@ -916,7 +909,7 @@ export default function SmartWorkspaceNameField({ onValueChange={(next) => { const nextMode = next as SmartNameMode setMode(nextMode) - setOpen(!disabled && nextMode !== 'text') + setOpen(!disabled && nextMode !== 'text' && selectedSource === null) cancelLocalInputFocusFrame() localInputFocusFrameRef.current = requestAnimationFrame(() => { localInputFocusFrameRef.current = null @@ -966,8 +959,8 @@ export default function SmartWorkspaceNameField({ setOpen(disabled ? false : next)} + open={!disabled && open && mode !== 'text' && selectedSource === null} + onOpenChange={(next) => setOpen(disabled || selectedSource ? false : next)} > { if (