Skip to content

Commit 2dceadb

Browse files
authored
Merge pull request RooCodeInc#1294 from evan-fannin/cline-terminals-fix
Fix: multiple terminals created
2 parents 7191b0a + c9b3732 commit 2dceadb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/integrations/terminal/TerminalManager.ts

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

159159
async getOrCreateTerminal(cwd: string): Promise<TerminalInfo> {
160+
const terminals = TerminalRegistry.getAllTerminals()
161+
160162
// Find available terminal from our pool first (created for this task)
161-
const availableTerminal = TerminalRegistry.getAllTerminals().find((t) => {
163+
const matchingTerminal = terminals.find((t) => {
162164
if (t.busy) {
163165
return false
164166
}
@@ -168,11 +170,21 @@ export class TerminalManager {
168170
}
169171
return arePathsEqual(vscode.Uri.file(cwd).fsPath, terminalCwd.fsPath)
170172
})
173+
if (matchingTerminal) {
174+
this.terminalIds.add(matchingTerminal.id)
175+
return matchingTerminal
176+
}
177+
178+
// If no matching terminal exists, try to find any non-busy terminal
179+
const availableTerminal = terminals.find((t) => !t.busy)
171180
if (availableTerminal) {
181+
// Navigate back to the desired directory
182+
await this.runCommand(availableTerminal, `cd "${cwd}"`)
172183
this.terminalIds.add(availableTerminal.id)
173184
return availableTerminal
174185
}
175186

187+
// If all terminals are busy, create a new one
176188
const newTerminalInfo = TerminalRegistry.createTerminal(cwd)
177189
this.terminalIds.add(newTerminalInfo.id)
178190
return newTerminalInfo

0 commit comments

Comments
 (0)