@@ -34,7 +34,7 @@ export async function openInteractiveREPL(
3434 // Case where NotebookDocument doesnt exist, create a blank one.
3535 notebookDocument = await workspace . openNotebookDocument ( 'jupyter-notebook' ) ;
3636 }
37- const editor = window . showNotebookDocument ( notebookDocument ! , { viewColumn, asRepl : true , label : 'Python REPL' } ) ;
37+ const editor = window . showNotebookDocument ( notebookDocument ! , { viewColumn, asRepl : 'Python REPL' } ) ;
3838 await commands . executeCommand ( 'notebook.selectKernel' , {
3939 editor,
4040 id : notebookController . id ,
@@ -69,13 +69,14 @@ export async function selectNotebookKernel(
6969 * @param code
7070 * @return Promise<void>
7171 */
72- export async function executeNotebookCell ( notebookDocument : NotebookDocument , code : string ) : Promise < void > {
73- const { cellCount } = notebookDocument ;
74- await addCellToNotebook ( notebookDocument , code ) ;
72+ export async function executeNotebookCell ( notebookEditor : NotebookEditor , code : string ) : Promise < void > {
73+ const { notebook, replOptions } = notebookEditor ;
74+ const cellIndex = replOptions ?. appendIndex ?? notebook . cellCount ;
75+ await addCellToNotebook ( notebook , cellIndex , code ) ;
7576 // Execute the cell
7677 commands . executeCommand ( 'notebook.cell.execute' , {
77- ranges : [ { start : cellCount - 1 , end : cellCount } ] ,
78- document : notebookDocument . uri ,
78+ ranges : [ { start : cellIndex , end : cellIndex + 1 } ] ,
79+ document : notebook . uri ,
7980 } ) ;
8081}
8182
@@ -85,11 +86,10 @@ export async function executeNotebookCell(notebookDocument: NotebookDocument, co
8586 * @param code
8687 *
8788 */
88- async function addCellToNotebook ( notebookDocument : NotebookDocument , code : string ) : Promise < void > {
89+ async function addCellToNotebook ( notebookDocument : NotebookDocument , index : number , code : string ) : Promise < void > {
8990 const notebookCellData = new NotebookCellData ( NotebookCellKind . Code , code as string , 'python' ) ;
90- const { cellCount } = notebookDocument ! ;
9191 // Add new cell to interactive window document
92- const notebookEdit = NotebookEdit . insertCells ( cellCount - 1 , [ notebookCellData ] ) ;
92+ const notebookEdit = NotebookEdit . insertCells ( index , [ notebookCellData ] ) ;
9393 const workspaceEdit = new WorkspaceEdit ( ) ;
9494 workspaceEdit . set ( notebookDocument ! . uri , [ notebookEdit ] ) ;
9595 await workspace . applyEdit ( workspaceEdit ) ;
0 commit comments