@@ -6,14 +6,14 @@ import {
66 NotebookControllerAffinity ,
77 NotebookDocument ,
88 QuickPickItem ,
9- TabInputText ,
109 TextEditor ,
1110 Uri ,
1211 workspace ,
1312 WorkspaceFolder ,
1413 window ,
15- TabInputTextDiff ,
1614 TabInputNotebook ,
15+ TabInputTextDiff ,
16+ TabInputText ,
1717} from 'vscode' ;
1818import { Disposable } from 'vscode-jsonrpc' ;
1919import * as path from 'path' ;
@@ -174,13 +174,25 @@ export class NativeRepl implements Disposable {
174174 ) ;
175175 await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , this . replUri . toString ( ) ) ;
176176 const myFileName = path . basename ( this . replUri . fsPath ) ;
177- const whatever = 'hi' ;
178- const tabNames = getOpenTabNames ( ) ;
177+
178+ // const tabNames = getOpenTabNames();
179+ const tabLabel = getTabNameForUri ( this . replUri ) ;
180+ if ( tabLabel !== 'Python REPL' ) {
181+ const regex = / ^ U n t i t l e d - \d + \. i p y n b $ / ;
182+ const isUntitled = regex . test ( myFileName ) ;
183+
184+ this . replUri = undefined ;
185+ mementoUri = undefined ;
186+
187+ await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , undefined ) ;
188+ this . notebookDocument = undefined ;
189+ }
179190 }
180191 } else {
181192 this . replUri = undefined ;
182193 mementoUri = undefined ;
183194 await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , undefined ) ;
195+ this . notebookDocument = undefined ;
184196 }
185197
186198 const notebookEditor = await openInteractiveREPL ( this . replController , this . notebookDocument , mementoUri ) ;
@@ -208,10 +220,34 @@ function getOpenTabNames(): string[] {
208220 tabNames . push ( tab . label ) ;
209221 }
210222 }
211-
223+ // TODO if tabName includes 'Python REPL' and there are other 'Untitled-*.ipynb' then, we need to re-create REPL instance with new URI.
212224 return tabNames ;
213225}
214226
227+ function getTabNameForUri ( uri : Uri ) : string | undefined {
228+ const tabGroups = window . tabGroups . all ;
229+
230+ for ( const tabGroup of tabGroups ) {
231+ for ( const tab of tabGroup . tabs ) {
232+ if ( tab . input instanceof TabInputText && tab . input . uri . toString ( ) === uri . toString ( ) ) {
233+ return tab . label ;
234+ }
235+ if ( tab . input instanceof TabInputTextDiff ) {
236+ if (
237+ tab . input . original . toString ( ) === uri . toString ( ) ||
238+ tab . input . modified . toString ( ) === uri . toString ( )
239+ ) {
240+ return tab . label ;
241+ }
242+ } else if ( tab . input instanceof TabInputNotebook && tab . input . uri . toString ( ) === uri . toString ( ) ) {
243+ return tab . label ;
244+ }
245+ }
246+ }
247+
248+ return undefined ;
249+ }
250+
215251/**
216252 * Get Singleton Native REPL Instance
217253 * @param interpreter
0 commit comments