File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
src/integrations/terminal Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments