Skip to content

Commit 2dfe2c5

Browse files
authored
Merge pull request #552 from RooVetGit/fix_multiple_terminals_created
Fix multiple terminals created
2 parents bf49b3e + 68712ea commit 2dfe2c5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Fix issue where the terminal management system was creating unnecessary new terminals (thanks @evan-fannin!)

src/integrations/terminal/TerminalManager.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ export class TerminalManager {
161161
}
162162

163163
async getOrCreateTerminal(cwd: string): Promise<TerminalInfo> {
164+
const terminals = TerminalRegistry.getAllTerminals()
165+
164166
// Find available terminal from our pool first (created for this task)
165-
const availableTerminal = TerminalRegistry.getAllTerminals().find((t) => {
167+
const matchingTerminal = terminals.find((t) => {
166168
if (t.busy) {
167169
return false
168170
}
@@ -173,11 +175,21 @@ export class TerminalManager {
173175
}
174176
return arePathsEqual(vscode.Uri.file(cwd).fsPath, terminalCwd.fsPath)
175177
})
178+
if (matchingTerminal) {
179+
this.terminalIds.add(matchingTerminal.id)
180+
return matchingTerminal
181+
}
182+
183+
// If no matching terminal exists, try to find any non-busy terminal
184+
const availableTerminal = terminals.find((t) => !t.busy)
176185
if (availableTerminal) {
186+
// Navigate back to the desired directory
187+
await this.runCommand(availableTerminal, `cd "${cwd}"`)
177188
this.terminalIds.add(availableTerminal.id)
178189
return availableTerminal
179190
}
180191

192+
// If all terminals are busy, create a new one
181193
const newTerminalInfo = TerminalRegistry.createTerminal(cwd)
182194
this.terminalIds.add(newTerminalInfo.id)
183195
return newTerminalInfo

0 commit comments

Comments
 (0)