mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 00:02:31 +00:00
fix: cancel untitled rename focus frame (#3434)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useRef, useState } from 'react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { FolderOpen } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@@ -36,6 +36,7 @@ export function UntitledFileRenameDialog({
|
||||
const [dir, setDir] = useState(worktreePath)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const nameInputRef = useRef<HTMLInputElement>(null)
|
||||
const focusFrameRef = useRef<number | null>(null)
|
||||
const seededOpenStateRef = useRef({ open: false, baseName, worktreePath })
|
||||
|
||||
const displayError = externalError ?? error
|
||||
@@ -54,6 +55,15 @@ export function UntitledFileRenameDialog({
|
||||
seededOpenStateRef.current = { open: false, baseName, worktreePath }
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (focusFrameRef.current !== null) {
|
||||
cancelAnimationFrame(focusFrameRef.current)
|
||||
focusFrameRef.current = null
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleBrowse = useCallback(async () => {
|
||||
const picked = await window.api.shell.pickDirectory({ defaultPath: dir || worktreePath })
|
||||
if (!picked) {
|
||||
@@ -98,7 +108,11 @@ export function UntitledFileRenameDialog({
|
||||
className="max-w-[340px]"
|
||||
onOpenAutoFocus={(event) => {
|
||||
event.preventDefault()
|
||||
requestAnimationFrame(() => {
|
||||
if (focusFrameRef.current !== null) {
|
||||
cancelAnimationFrame(focusFrameRef.current)
|
||||
}
|
||||
focusFrameRef.current = requestAnimationFrame(() => {
|
||||
focusFrameRef.current = null
|
||||
nameInputRef.current?.focus()
|
||||
nameInputRef.current?.select()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user