@@ -218,27 +218,37 @@ export class RNotebookProvider implements vscode.NotebookContentProvider, vscode
218218 } ;
219219 }
220220
221- onDidChangeNotebook = new vscode . EventEmitter < vscode . NotebookDocumentEditEvent > ( ) . event ;
222- async resolveNotebook ( ) : Promise < void > { }
223- async saveNotebook ( document : vscode . NotebookDocument , cancellation : vscode . CancellationToken ) : Promise < void > {
221+ async save ( targetResource : vscode . Uri , document : vscode . NotebookDocument , cancellation : vscode . CancellationToken ) : Promise < void > {
224222 let content = '' ;
225223 for ( const cell of document . cells ) {
224+ if ( cancellation . isCancellationRequested ) {
225+ return ;
226+ }
226227 if ( cell . cellKind === vscode . CellKind . Markdown ) {
227- content += '\n\n' + cell . document . getText ( ) + '\n\n' ;
228+ content += cell . document . getText ( ) ;
228229 } else if ( cell . cellKind === vscode . CellKind . Code ) {
229230 if ( cell . language === 'r' ) {
230- content += '\n\n ```{r}\n' + cell . document . getText ( ) + '\n```\n' ;
231+ content += '```{r}\n' + cell . document . getText ( ) + '\n```\n \n' ;
231232 } else if ( cell . language === 'yaml' ) {
232233 content += '---\n' + cell . document . getText ( ) + '\n---\n' ;
233234 } else {
234- content += '\n\n ```{' + cell . language + '}\n' + cell . document . getText ( ) + '\n```\n' ;
235+ content += '```{' + cell . language + '}\n' + cell . document . getText ( ) + '\n```\n \n' ;
235236 }
236237 }
237238 }
238- vscode . workspace . fs . writeFile ( document . uri , Buffer . from ( content ) ) ;
239+ await vscode . workspace . fs . writeFile ( document . uri , Buffer . from ( content ) ) ;
240+ }
241+
242+ onDidChangeNotebook = new vscode . EventEmitter < vscode . NotebookDocumentEditEvent > ( ) . event ;
243+ async resolveNotebook ( ) : Promise < void > { }
244+ async saveNotebook ( document : vscode . NotebookDocument , cancellation : vscode . CancellationToken ) : Promise < void > {
245+ await this . save ( document . uri , document , cancellation ) ;
246+ }
247+
248+ async saveNotebookAs ( targetResource : vscode . Uri , document : vscode . NotebookDocument , cancellation : vscode . CancellationToken ) : Promise < void > {
249+ await this . save ( targetResource , document , cancellation ) ;
239250 }
240251
241- async saveNotebookAs ( targetResource : vscode . Uri , document : vscode . NotebookDocument , cancellation : vscode . CancellationToken ) : Promise < void > { }
242252 async backupNotebook ( document : vscode . NotebookDocument , context : vscode . NotebookDocumentBackupContext , cancellation : vscode . CancellationToken ) : Promise < vscode . NotebookDocumentBackup > { return { id : '' , delete : ( ) => { } } ; }
243253 async executeCell ( document : vscode . NotebookDocument , cell : vscode . NotebookCell ) {
244254 const notebook = this . notebooks . get ( document . uri . toString ( ) ) ;
0 commit comments