@@ -18,7 +18,7 @@ import { injectable, inject, optional } from '@theia/core/shared/inversify';
18
18
import { Position , Location } from '@theia/core/shared/vscode-languageserver-types' ;
19
19
import { CommandContribution , CommandRegistry , CommandHandler } from '@theia/core/lib/common/command' ;
20
20
import { CommonCommands , QuickInputService , ApplicationShell } from '@theia/core/lib/browser' ;
21
- import { EditorCommands , EditorManager } from '@theia/editor/lib/browser' ;
21
+ import { EditorCommands , EditorManager , EditorWidget } from '@theia/editor/lib/browser' ;
22
22
import { MonacoEditor } from './monaco-editor' ;
23
23
import { MonacoCommandRegistry , MonacoEditorCommandHandler } from './monaco-command-registry' ;
24
24
import { MonacoEditorService } from './monaco-editor-service' ;
@@ -191,6 +191,7 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
191
191
this . monacoCommandRegistry . registerHandler ( EditorCommands . CONFIG_EOL . id , this . newConfigEolHandler ( ) ) ;
192
192
this . monacoCommandRegistry . registerHandler ( EditorCommands . INDENT_USING_SPACES . id , this . newConfigTabSizeHandler ( true ) ) ;
193
193
this . monacoCommandRegistry . registerHandler ( EditorCommands . INDENT_USING_TABS . id , this . newConfigTabSizeHandler ( false ) ) ;
194
+ this . monacoCommandRegistry . registerHandler ( EditorCommands . REVERT_EDITOR . id , this . newRevertActiveEditorHandler ( ) ) ;
194
195
this . monacoCommandRegistry . registerHandler ( EditorCommands . REVERT_AND_CLOSE . id , this . newRevertAndCloseActiveEditorHandler ( ) ) ;
195
196
}
196
197
@@ -272,23 +273,36 @@ export class MonacoEditorCommandHandlers implements CommandContribution {
272
273
}
273
274
}
274
275
276
+ protected newRevertActiveEditorHandler ( ) : MonacoEditorCommandHandler {
277
+ return {
278
+ execute : ( ) => this . revertEditor ( this . getActiveEditor ( ) . editor ) ,
279
+ } ;
280
+ }
281
+
275
282
protected newRevertAndCloseActiveEditorHandler ( ) : MonacoEditorCommandHandler {
276
283
return {
277
- execute : async ( ) => this . revertAndCloseActiveEditor ( )
284
+ execute : async ( ) => this . revertAndCloseActiveEditor ( this . getActiveEditor ( ) )
278
285
} ;
279
286
}
280
287
281
- protected async revertAndCloseActiveEditor ( ) : Promise < void > {
282
- const editor = this . editorManager . currentEditor ;
288
+ protected getActiveEditor ( ) : { widget ?: EditorWidget , editor ?: MonacoEditor } {
289
+ const widget = this . editorManager . currentEditor ;
290
+ return { widget, editor : widget && MonacoEditor . getCurrent ( this . editorManager ) } ;
291
+ }
292
+
293
+ protected async revertEditor ( editor ?: MonacoEditor ) : Promise < void > {
283
294
if ( editor ) {
284
- const monacoEditor = MonacoEditor . getCurrent ( this . editorManager ) ;
285
- if ( monacoEditor ) {
286
- try {
287
- await monacoEditor . document . revert ( ) ;
288
- editor . close ( ) ;
289
- } catch ( error ) {
290
- await this . shell . closeWidget ( editor . id , { save : false } ) ;
291
- }
295
+ return editor . document . revert ( ) ;
296
+ }
297
+ }
298
+
299
+ protected async revertAndCloseActiveEditor ( current : { widget ?: EditorWidget , editor ?: MonacoEditor } ) : Promise < void > {
300
+ if ( current . editor && current . widget ) {
301
+ try {
302
+ await this . revertEditor ( current . editor ) ;
303
+ current . widget . close ( ) ;
304
+ } catch ( error ) {
305
+ await this . shell . closeWidget ( current . widget . id , { save : false } ) ;
292
306
}
293
307
}
294
308
}
0 commit comments