From 7239bb2c33520dde39c6cdfca2d8eece409b7524 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 23 Feb 2017 10:50:59 +0100 Subject: [PATCH] fix #19287 --- .../browser/parts/editor/textDiffEditor.ts | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index d1b2616d085..bc385a4e317 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -281,24 +281,8 @@ export class TextDiffEditor extends BaseTextEditor { public getSecondaryActions(): IAction[] { const actions = super.getSecondaryActions(); - const control = this.getControl(); - - let inlineModeActive = control && !control.renderSideBySide; - const inlineLabel = nls.localize('inlineDiffLabel', "Switch to Inline View"); - const sideBySideLabel = nls.localize('sideBySideDiffLabel', "Switch to Side by Side View"); - // Action to toggle editor mode from inline to side by side - const toggleEditorModeAction = new Action('toggle.diff.editorMode', inlineModeActive ? sideBySideLabel : inlineLabel, null, true, () => { - this.getControl().updateOptions({ - renderSideBySide: inlineModeActive - }); - - inlineModeActive = !inlineModeActive; - toggleEditorModeAction.label = inlineModeActive ? sideBySideLabel : inlineLabel; - - return TPromise.as(true); - }); - + const toggleEditorModeAction = new ToggleEditorModeAction(this); toggleEditorModeAction.order = 50; // Closer to the end actions.push(...[ @@ -354,4 +338,35 @@ class NavigateAction extends Action { public updateEnablement(): void { this.enabled = this.editor.getDiffNavigator().canNavigate(); } +} + +class ToggleEditorModeAction extends Action { + private static ID = 'toggle.diff.editorMode'; + private static INLINE_LABEL = nls.localize('inlineDiffLabel', "Switch to Inline View"); + private static SIDEBYSIDE_LABEL = nls.localize('sideBySideDiffLabel', "Switch to Side by Side View"); + + constructor(private editor: TextDiffEditor) { + super(ToggleEditorModeAction.ID); + } + + public get label(): string { + return ToggleEditorModeAction.isInlineMode(this.editor) ? ToggleEditorModeAction.SIDEBYSIDE_LABEL : ToggleEditorModeAction.INLINE_LABEL; + } + + public run(): TPromise { + const inlineModeActive = ToggleEditorModeAction.isInlineMode(this.editor); + + const control = this.editor.getControl(); + control.updateOptions({ + renderSideBySide: inlineModeActive + }); + + return TPromise.as(true); + } + + private static isInlineMode(editor: TextDiffEditor): boolean { + const control = editor.getControl(); + + return control && !control.renderSideBySide; + } } \ No newline at end of file