@@ -53,6 +53,15 @@ function getSendToNativeREPLSetting(): boolean {
53
53
const configuration = getConfiguration ( 'python' , uri ) ;
54
54
return configuration . get < boolean > ( 'REPL.sendToNativeREPL' , false ) ;
55
55
}
56
+
57
+ window . onDidChangeVisibleTextEditors ( ( editors ) => {
58
+ const interactiveWindowIsOpen = editors . some ( ( editor ) => editor . document . uri . scheme === 'vscode-interactive-input' ) ;
59
+ if ( ! interactiveWindowIsOpen ) {
60
+ notebookEditor = undefined ;
61
+ notebookDocument = undefined ;
62
+ }
63
+ } ) ;
64
+
56
65
// Will only be called when user has experiment enabled.
57
66
export async function registerReplCommands (
58
67
disposables : Disposable [ ] ,
@@ -82,18 +91,24 @@ export async function registerReplCommands(
82
91
const activeEditor = window . activeTextEditor as TextEditor ;
83
92
const code = await getSelectedTextToExecute ( activeEditor ) ;
84
93
85
- const interactiveWindowObject = ( await commands . executeCommand (
86
- 'interactive.open' ,
87
- {
88
- preserveFocus : true ,
89
- viewColumn : ViewColumn . Beside ,
90
- } ,
91
- undefined ,
92
- notebookController . id ,
93
- 'Python REPL' ,
94
- ) ) as { notebookEditor : NotebookEditor } ;
95
- notebookEditor = interactiveWindowObject . notebookEditor ;
96
- notebookDocument = interactiveWindowObject . notebookEditor . notebook ;
94
+ if ( ! notebookEditor ) {
95
+ const interactiveWindowObject = ( await commands . executeCommand (
96
+ 'interactive.open' ,
97
+ {
98
+ preserveFocus : true ,
99
+ viewColumn : ViewColumn . Beside ,
100
+ } ,
101
+ undefined ,
102
+ notebookController . id ,
103
+ 'Python REPL' ,
104
+ ) ) as { notebookEditor : NotebookEditor } ;
105
+ notebookEditor = interactiveWindowObject . notebookEditor ;
106
+ notebookDocument = interactiveWindowObject . notebookEditor . notebook ;
107
+ }
108
+ // Handle case where user has closed REPL window, and re-opens.
109
+ if ( notebookEditor && notebookDocument ) {
110
+ await window . showNotebookDocument ( notebookDocument , { viewColumn : ViewColumn . Beside } ) ;
111
+ }
97
112
98
113
if ( notebookDocument ) {
99
114
notebookController . updateNotebookAffinity ( notebookDocument , NotebookControllerAffinity . Default ) ;
0 commit comments