Skip to content

Commit

Permalink
Support for VSCode Command workbench.action.revertAndCloseActiveEditor
Browse files Browse the repository at this point in the history
- Force close of editor in case document.revert fails

Signed-off-by: Ignacio Moreno <ignacio@genuitec.com>
  • Loading branch information
nmorenor authored and akosyakov committed May 1, 2020
1 parent 0d58113 commit 0f931f2
Showing 1 changed file with 18 additions and 0 deletions.
Expand Up @@ -51,6 +51,7 @@ import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { inject, injectable } from 'inversify';
import { Position } from '@theia/plugin-ext/lib/common/plugin-api-rpc';
import { URI } from 'vscode-uri';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';

export namespace VscodeCommands {
export const OPEN: Command = {
Expand Down Expand Up @@ -330,6 +331,23 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
}
});

commands.registerCommand({ id: 'workbench.action.revertAndCloseActiveEditor' }, {
execute: async () => {
const editor = this.editorManager.currentEditor;
if (editor) {
const monacoEditor = MonacoEditor.getCurrent(this.editorManager);
if (monacoEditor) {
try {
await monacoEditor.document.revert();
editor.close();
} catch (error) {
await this.shell.closeWidget(editor.id, { save: false });
}
}
}
}
});

/**
* TODO:
* Keep Open workbench.action.keepEditor
Expand Down

0 comments on commit 0f931f2

Please sign in to comment.