@@ -123,18 +123,26 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit<Registe
123123 // don't need to use that event).
124124 // https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
125125 const tabProvider = new ClineProvider ( context , outputChannel , "editor" )
126- const lastCol = Math . max ( ...vscode . window . visibleTextEditors . map ( ( editor ) => editor . viewColumn || 0 ) )
127126
128- // Check if there are any visible text editors, otherwise open a new group
129- // to the right.
127+ const activeEditor = vscode . window . activeTextEditor
130128 const hasVisibleEditors = vscode . window . visibleTextEditors . length > 0
131129
130+ let targetCol : vscode . ViewColumn
131+
132132 if ( ! hasVisibleEditors ) {
133+ // No editors open, open in first column
134+ targetCol = vscode . ViewColumn . One
135+ } else if ( activeEditor && activeEditor . document . isUntitled && vscode . window . visibleTextEditors . length === 1 ) {
136+ // Only one editor and it's empty (untitled), reuse it
137+ targetCol = activeEditor . viewColumn ?? vscode . ViewColumn . One
138+ } else {
139+ // Otherwise, create a new group to the right
133140 await vscode . commands . executeCommand ( "workbench.action.newGroupRight" )
141+ // New group becomes the last + 1
142+ const lastCol = Math . max ( ...vscode . window . visibleTextEditors . map ( ( e ) => e . viewColumn || 1 ) )
143+ targetCol = ( lastCol + 1 ) as vscode . ViewColumn
134144 }
135145
136- const targetCol = hasVisibleEditors ? Math . max ( lastCol + 1 , 1 ) : vscode . ViewColumn . Two
137-
138146 const newPanel = vscode . window . createWebviewPanel ( ClineProvider . tabPanelId , "Roo Code" , targetCol , {
139147 enableScripts : true ,
140148 retainContextWhenHidden : true ,
0 commit comments