@@ -28,6 +28,7 @@ export class Editor {
28
28
_instanceState : ShellInstanceState ;
29
29
_loadExternalCode : ( input : string , filename : string ) => Promise < ShellResult > ;
30
30
_lastContent : string ;
31
+ _lastInputCode : string ;
31
32
print : ( ...args : any [ ] ) => Promise < void > ;
32
33
33
34
constructor ( { input, vscodeDir, tmpDir, instanceState, loadExternalCode } : EditorOptions ) {
@@ -37,6 +38,7 @@ export class Editor {
37
38
this . _instanceState = instanceState ;
38
39
this . _loadExternalCode = loadExternalCode ;
39
40
this . _lastContent = '' ;
41
+ this . _lastInputCode = '' ;
40
42
this . print = instanceState . context . print ;
41
43
42
44
// Add edit command support to shell api.
@@ -173,6 +175,19 @@ export class Editor {
173
175
return `${ originalCode } = ${ modifiedCode } ` ;
174
176
}
175
177
178
+ _setLastInputCode ( code : string ) : void {
179
+ if ( code !== '' ) {
180
+ this . _lastInputCode = code ;
181
+ }
182
+ }
183
+
184
+ _getLastInputCode ( code : string ) : string {
185
+ if ( code !== '' ) {
186
+ return code ;
187
+ }
188
+ return this . _lastInputCode ;
189
+ }
190
+
176
191
async runEditCommand ( code : string ) : Promise < void > {
177
192
await this . print ( 'Opening an editor...' ) ;
178
193
@@ -183,6 +198,8 @@ export class Editor {
183
198
throw new Error ( 'Command failed with an error: please define an external editor' ) ;
184
199
}
185
200
201
+ this . _setLastInputCode ( code ) ;
202
+
186
203
const content = await this . _getEditorContent ( code ) ;
187
204
const ext = await this . _getExtension ( editor ) ;
188
205
const tmpDoc = await this . _createTempFile ( { content, ext } ) ;
@@ -208,7 +225,7 @@ export class Editor {
208
225
209
226
if ( exitCode === 0 ) {
210
227
const modifiedCode = await this . _readAndDeleteTempFile ( tmpDoc ) ;
211
- const result = this . _prepareResult ( { originalCode : code , modifiedCode } ) ;
228
+ const result = this . _prepareResult ( { originalCode : this . _getLastInputCode ( code ) , modifiedCode } ) ;
212
229
213
230
// Write a content from the editor to the parent readable stream.
214
231
this . _input . unshift ( result ) ;
0 commit comments