From 536d3d7c8fdcd3abc582e8e2bfefd4511a88f6fe Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 29 May 2026 03:43:29 -0700 Subject: [PATCH] Remove untitled rename reset effect (#3083) --- .../editor/UntitledFileRenameDialog.tsx | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx b/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx index 3ade1822693..187b1fe7dcb 100644 --- a/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx +++ b/src/renderer/src/components/editor/UntitledFileRenameDialog.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useRef, useState } from 'react' +import React, { useCallback, useRef, useState } from 'react' import { FolderOpen } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' @@ -36,19 +36,23 @@ export function UntitledFileRenameDialog({ const [dir, setDir] = useState(worktreePath) const [error, setError] = useState(null) const nameInputRef = useRef(null) + const seededOpenStateRef = useRef({ open: false, baseName, worktreePath }) const displayError = externalError ?? error - useEffect(() => { - if (open) { + // Why: seed the drafts before the open dialog paints; focus is handled by + // Radix's open lifecycle below so this does not need a post-render Effect. + if (open) { + const seeded = seededOpenStateRef.current + if (!seeded.open || seeded.baseName !== baseName || seeded.worktreePath !== worktreePath) { + seededOpenStateRef.current = { open: true, baseName, worktreePath } setName(baseName) setDir(worktreePath) setError(null) - requestAnimationFrame(() => { - nameInputRef.current?.select() - }) } - }, [open, baseName, worktreePath]) + } else if (seededOpenStateRef.current.open) { + seededOpenStateRef.current = { open: false, baseName, worktreePath } + } const handleBrowse = useCallback(async () => { const picked = await window.api.shell.pickDirectory({ defaultPath: dir || worktreePath }) @@ -89,7 +93,17 @@ export function UntitledFileRenameDialog({ return ( !isOpen && onClose()}> - + { + event.preventDefault() + requestAnimationFrame(() => { + nameInputRef.current?.focus() + nameInputRef.current?.select() + }) + }} + > Save as