@@ -158,36 +158,28 @@ export class NativeRepl implements Disposable {
158158 public async sendToNativeRepl ( code ?: string ) : Promise < void > {
159159 const mementoValue = ( await this . context . globalState . get ( NATIVE_REPL_URI_MEMENTO ) ) as string | undefined ;
160160 let mementoUri = mementoValue ? Uri . parse ( mementoValue ) : undefined ;
161+ const openNotebookDocuments = workspace . notebookDocuments . map ( ( doc ) => doc . uri ) ;
161162
162- // const mementoFsPath = mementoUri?.fsPath;
163-
164- const openEditors = workspace . textDocuments . map ( ( doc ) => doc . uri ) ;
165- const openEditorsFsPath = workspace . textDocuments . map ( ( doc ) => doc . uri . fsPath ) ;
166- // TODO need to check if that memento URI exist in my tab
167- // plain untitled notebook same uri as REPL.
168- // editor option check
169- if ( mementoUri ?. fsPath ) {
170- const matchingEditor = openEditors . find ( ( uri ) => uri . fsPath === mementoUri ?. fsPath ) ;
171- if ( matchingEditor ) {
172- this . replUri = matchingEditor ;
163+ if ( mementoUri ) {
164+ const replTabBeforeReload = openNotebookDocuments . find ( ( uri ) => uri . fsPath === mementoUri ?. fsPath ) ;
165+ if ( replTabBeforeReload ) {
166+ this . replUri = replTabBeforeReload ;
173167 this . notebookDocument = workspace . notebookDocuments . find (
174- ( doc ) => doc . uri . fsPath === matchingEditor . fsPath ,
168+ ( doc ) => doc . uri . fsPath === replTabBeforeReload . fsPath ,
175169 ) ;
176170 await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , this . replUri . toString ( ) ) ;
177171 }
178172 } else {
179173 this . replUri = undefined ;
180- await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , undefined ) ;
181174 mementoUri = undefined ;
175+ await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , undefined ) ;
182176 }
183177
184- // try to restore notebook doc based on memento value.
185- // if I cant, then clear momento and openInteractiveREPL.
186-
187178 const notebookEditor = await openInteractiveREPL ( this . replController , this . notebookDocument , mementoUri ) ;
179+
188180 this . notebookDocument = notebookEditor . notebook ;
189181 this . replUri = this . notebookDocument . uri ;
190- await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , this . replUri . toString ( ) ) ; // TODO store Uri as string and then parse this on recovery.
182+ await this . context . globalState . update ( NATIVE_REPL_URI_MEMENTO , this . replUri . toString ( ) ) ;
191183
192184 if ( this . notebookDocument ) {
193185 this . replController . updateNotebookAffinity ( this . notebookDocument , NotebookControllerAffinity . Default ) ;
0 commit comments