From d3130c0a74f50a5b0b7ba732a0cb4b53a8f24c9f Mon Sep 17 00:00:00 2001 From: Ignacio Moreno Date: Wed, 29 Apr 2020 16:13:10 -0500 Subject: [PATCH] Support for VSCode Command workbench.action.revertAndCloseActiveEditor - Force close of editor in case document.revert fails Signed-off-by: Ignacio Moreno --- .../plugin-vscode-commands-contribution.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts index cb891d55a17dd..bc1f5af9bd82a 100755 --- a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts +++ b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts @@ -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 = { @@ -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