@@ -50,15 +50,22 @@ export async function insertMarkdownCell(source: string) {
50
50
assert . fail ( 'No active editor' ) ;
51
51
return ;
52
52
}
53
- new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , activeEditor . document . cells . length , 0 , [
54
- {
55
- cellKind : vscodeNotebookEnums . CellKind . Markdown ,
56
- language : MARKDOWN_LANGUAGE ,
57
- source,
58
- metadata : { } ,
59
- outputs : [ ]
60
- }
61
- ] ) ;
53
+ new WorkspaceEdit ( ) . replaceCells (
54
+ activeEditor . document . uri ,
55
+ activeEditor . document . cells . length - 1 ,
56
+ activeEditor . document . cells . length - 1 ,
57
+ [
58
+ {
59
+ cellKind : vscodeNotebookEnums . CellKind . Markdown ,
60
+ language : MARKDOWN_LANGUAGE ,
61
+ source,
62
+ metadata : {
63
+ hasExecutionOrder : false
64
+ } ,
65
+ outputs : [ ]
66
+ }
67
+ ]
68
+ ) ;
62
69
63
70
await waitForCondition (
64
71
async ( ) =>
@@ -75,15 +82,22 @@ export async function insertPythonCell(source: string) {
75
82
assert . fail ( 'No active editor' ) ;
76
83
return ;
77
84
}
78
- new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , activeEditor . document . cells . length , 0 , [
79
- {
80
- cellKind : vscodeNotebookEnums . CellKind . Code ,
81
- language : PYTHON_LANGUAGE ,
82
- source,
83
- metadata : { } ,
84
- outputs : [ ]
85
- }
86
- ] ) ;
85
+ new WorkspaceEdit ( ) . replaceCells (
86
+ activeEditor . document . uri ,
87
+ activeEditor . document . cells . length - 1 ,
88
+ activeEditor . document . cells . length - 1 ,
89
+ [
90
+ {
91
+ cellKind : vscodeNotebookEnums . CellKind . Code ,
92
+ language : PYTHON_LANGUAGE ,
93
+ source,
94
+ metadata : {
95
+ hasExecutionOrder : false
96
+ } ,
97
+ outputs : [ ]
98
+ }
99
+ ]
100
+ ) ;
87
101
await waitForCondition (
88
102
async ( ) =>
89
103
activeEditor ?. document . cells [ activeEditor . document . cells . length - 1 ] . document . getText ( ) . trim ( ) ===
@@ -108,15 +122,15 @@ export async function deleteCell(index: number = 0) {
108
122
assert . fail ( 'No active editor' ) ;
109
123
return ;
110
124
}
111
- new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , index , 1 , [ ] ) ;
125
+ new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , index , index , [ ] ) ;
112
126
}
113
127
export async function deleteAllCellsAndWait ( ) {
114
128
const { vscodeNotebook } = await getServices ( ) ;
115
129
const activeEditor = vscodeNotebook . activeNotebookEditor ;
116
130
if ( ! activeEditor || activeEditor . document . cells . length === 0 ) {
117
131
return ;
118
132
}
119
- new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , 0 , activeEditor . document . cells . length , [ ] ) ;
133
+ new WorkspaceEdit ( ) . replaceCells ( activeEditor . document . uri , 0 , activeEditor . document . cells . length - 1 , [ ] ) ;
120
134
// Wait for cell to get deleted.
121
135
await waitForCondition ( async ( ) => activeEditor . document . cells . length === 0 , 1_000 , 'Cell not deleted' ) ;
122
136
}
0 commit comments