@@ -319,6 +319,70 @@ suite('notebook working copy', () => {
319319
320320 await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
321321 } ) ;
322+
323+ test ( 'multiple tabs: dirty + clean' , async function ( ) {
324+ const resource = vscode . Uri . parse ( join ( vscode . workspace . rootPath || '' , './first.vsctestnb' ) ) ;
325+ await vscode . commands . executeCommand ( 'vscode.openWith' , resource , 'notebookCoreTest' ) ;
326+
327+ await waitFor ( 500 ) ;
328+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellBelow' ) ;
329+ assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. source , '' ) ;
330+
331+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellAbove' ) ;
332+ await vscode . commands . executeCommand ( 'default:type' , { text : 'var abc = 0;' } ) ;
333+
334+ const secondResource = vscode . Uri . parse ( join ( vscode . workspace . rootPath || '' , './second.vsctestnb' ) ) ;
335+ await vscode . commands . executeCommand ( 'vscode.openWith' , secondResource , 'notebookCoreTest' ) ;
336+ await waitFor ( 500 ) ;
337+ await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
338+
339+ // make sure that the previous dirty editor is still restored in the extension host and no data loss
340+ assert . equal ( vscode . notebook . activeNotebookEditor !== undefined , true ) ;
341+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection !== undefined , true ) ;
342+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells [ 1 ] , vscode . notebook . activeNotebookEditor ?. selection ) ;
343+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells . length , 3 ) ;
344+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection ?. source , 'var abc = 0;' ) ;
345+
346+ await vscode . commands . executeCommand ( 'workbench.action.files.save' ) ;
347+ await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
348+ } ) ;
349+
350+ test ( 'multiple tabs: two dirty tabs and switching' , async function ( ) {
351+ const resource = vscode . Uri . parse ( join ( vscode . workspace . rootPath || '' , './first.vsctestnb' ) ) ;
352+ await vscode . commands . executeCommand ( 'vscode.openWith' , resource , 'notebookCoreTest' ) ;
353+
354+ await waitFor ( 500 ) ;
355+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellBelow' ) ;
356+ assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. source , '' ) ;
357+
358+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellAbove' ) ;
359+ await vscode . commands . executeCommand ( 'default:type' , { text : 'var abc = 0;' } ) ;
360+
361+ const secondResource = vscode . Uri . parse ( join ( vscode . workspace . rootPath || '' , './second.vsctestnb' ) ) ;
362+ await vscode . commands . executeCommand ( 'vscode.openWith' , secondResource , 'notebookCoreTest' ) ;
363+ await waitFor ( 500 ) ;
364+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellBelow' ) ;
365+ assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. source , '' ) ;
366+
367+ // switch to the first editor
368+ await vscode . commands . executeCommand ( 'vscode.openWith' , resource , 'notebookCoreTest' ) ;
369+ assert . equal ( vscode . notebook . activeNotebookEditor !== undefined , true ) ;
370+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection !== undefined , true ) ;
371+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells [ 1 ] , vscode . notebook . activeNotebookEditor ?. selection ) ;
372+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells . length , 3 ) ;
373+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection ?. source , 'var abc = 0;' ) ;
374+
375+ // switch to the second editor
376+ await vscode . commands . executeCommand ( 'vscode.openWith' , secondResource , 'notebookCoreTest' ) ;
377+ assert . equal ( vscode . notebook . activeNotebookEditor !== undefined , true ) ;
378+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection !== undefined , true ) ;
379+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells [ 1 ] , vscode . notebook . activeNotebookEditor ?. selection ) ;
380+ assert . deepEqual ( vscode . notebook . activeNotebookEditor ?. document . cells . length , 2 ) ;
381+ assert . equal ( vscode . notebook . activeNotebookEditor ?. selection ?. source , '' ) ;
382+
383+ await vscode . commands . executeCommand ( 'workbench.action.files.saveAll' ) ;
384+ await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' ) ;
385+ } ) ;
322386} ) ;
323387
324388suite ( 'metadata' , ( ) => {
@@ -344,6 +408,25 @@ suite('regression', () => {
344408 assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. source , '' ) ;
345409 assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. language , 'typescript' ) ;
346410 } ) ;
411+
412+ test ( '#97830, #97764. Support switch to other editor types' , async function ( ) {
413+ const resource = vscode . Uri . parse ( join ( vscode . workspace . rootPath || '' , './empty.vsctestnb' ) ) ;
414+ await vscode . commands . executeCommand ( 'vscode.openWith' , resource , 'notebookCoreTest' ) ;
415+
416+ await waitFor ( 500 ) ;
417+ await vscode . commands . executeCommand ( 'notebook.cell.insertCodeCellBelow' ) ;
418+ await vscode . commands . executeCommand ( 'default:type' , { text : 'var abc = 0;' } ) ;
419+
420+ assert . equal ( vscode . notebook . activeNotebookEditor !== undefined , true , 'notebook first' ) ;
421+ assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. source , 'var abc = 0;' ) ;
422+ assert . equal ( vscode . notebook . activeNotebookEditor ! . selection ?. language , 'typescript' ) ;
423+
424+ await vscode . commands . executeCommand ( 'vscode.openWith' , resource , 'default' ) ;
425+ assert . equal ( vscode . window . activeTextEditor ?. document . uri . path , resource . path ) ;
426+
427+ await vscode . commands . executeCommand ( 'workbench.action.files.saveAll' ) ;
428+ await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' ) ;
429+ } ) ;
347430} ) ;
348431
349432suite ( 'webview resource uri' , ( ) => {
0 commit comments