fix: update run button state when terminal tab is closed directly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xintaofei
2026-04-03 10:42:50 +08:00
parent 9396127cd9
commit ea3b20b2d9

View File

@@ -41,7 +41,11 @@ function setSelectedCommandId(folderId: number, cmdId: number) {
export function CommandDropdown() { export function CommandDropdown() {
const t = useTranslations("Folder.commandDropdown") const t = useTranslations("Folder.commandDropdown")
const { folder } = useFolderContext() const { folder } = useFolderContext()
const { createTerminalWithCommand, exitedTerminals } = useTerminalContext() const {
createTerminalWithCommand,
exitedTerminals,
tabs: terminalTabs,
} = useTerminalContext()
const [commands, setCommands] = useState<FolderCommand[]>([]) const [commands, setCommands] = useState<FolderCommand[]>([])
const [manageOpen, setManageOpen] = useState(false) const [manageOpen, setManageOpen] = useState(false)
const [bootstrapping, setBootstrapping] = useState(false) const [bootstrapping, setBootstrapping] = useState(false)
@@ -77,6 +81,23 @@ export function CommandDropdown() {
}) })
}, [exitedTerminals]) }, [exitedTerminals])
// React to terminal tabs being closed (e.g. user closes the tab directly)
useEffect(() => {
setRunningCommandTerminals((prev) => {
if (Object.keys(prev).length === 0) return prev
const tabIds = new Set(terminalTabs.map((t) => t.id))
let changed = false
const next = { ...prev }
for (const [cmdId, termId] of Object.entries(prev)) {
if (!tabIds.has(termId)) {
delete next[Number(cmdId)]
changed = true
}
}
return changed ? next : prev
})
}, [terminalTabs])
const selectCommand = useCallback( const selectCommand = useCallback(
(commandId: number) => { (commandId: number) => {
if (!folderId) return if (!folderId) return