提交 8c91f01f 编写于 作者: A Alex Dima

Fixes #9012: Add toggle for "ignore trim whitespace" while diffing

上级 04db94e3
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.st0{opacity:0}.st0,.st1{fill:#f6f6f6}.st2{fill:#424242}</style><g id="outline"><path class="st0" d="M0 0h16v16H0z"/><path class="st1" d="M12 4v8H4V4h8z"/></g><path class="st2" d="M5 9h6v2H5V9zm0-4v2h6V5H5z" id="icon_x5F_bg"/><rect fill="#000000" x="1" y="1" width="14" height="14" fill-opacity="0" stroke="#424242"></rect></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.st0{opacity:0}.st0,.st1{fill:#252526}.st2{fill:#c5c5c5}</style><g id="outline"><path class="st0" d="M0 0h16v16H0z"/><path class="st1" d="M12 4v8H4V4h8z"/></g><path class="st2" d="M5 9h6v2H5V9zm0-4v2h6V5H5z" id="icon_x5F_bg"/><rect fill="#000000" x="1" y="1" width="14" height="14" fill-opacity="0" stroke="#c5c5c5"></rect></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.st0{opacity:0}.st0,.st1{fill:#f6f6f6}.st2{fill:#424242}</style><g id="outline"><path class="st0" d="M0 0h16v16H0z"/><path class="st1" d="M12 4v8H4V4h8z"/></g><path class="st2" d="M5 9h6v2H5V9zm0-4v2h6V5H5z" id="icon_x5F_bg"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><style>.st0{opacity:0}.st0,.st1{fill:#252526}.st2{fill:#c5c5c5}</style><g id="outline"><path class="st0" d="M0 0h16v16H0z"/><path class="st1" d="M12 4v8H4V4h8z"/></g><path class="st2" d="M5 9h6v2H5V9zm0-4v2h6V5H5z" id="icon_x5F_bg"/></svg>
\ No newline at end of file
......@@ -19,4 +19,20 @@
.vs-dark .monaco-workbench .textdiff-editor-action.previous,
.hc-black .monaco-workbench .textdiff-editor-action.previous {
background: url('previous-diff-inverse.svg') center center no-repeat;
}
\ No newline at end of file
}
.vs .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace {
background: url('IgnoreTrimWhiteSpace_16x.svg') center center no-repeat;
}
.vs-dark .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace,
.hc-black .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace {
background: url('IgnoreTrimWhiteSpace_16x_inverse.svg ') center center no-repeat;
}
.vs .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace.is-checked {
background: url('IgnoreTrimWhiteSpaceChecked_16x.svg') center center no-repeat;
}
.vs-dark .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace.is-checked,
.hc-black .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace.is-checked {
background: url('IgnoreTrimWhiteSpaceChecked_16x_inverse.svg ') center center no-repeat;
}
......@@ -34,6 +34,8 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDisposable } from 'vs/base/common/lifecycle';
/**
* The text editor that leverages the diff text editor for the editing experience.
......@@ -45,18 +47,27 @@ export class TextDiffEditor extends BaseTextEditor {
private diffNavigator: DiffNavigator;
private nextDiffAction: NavigateAction;
private previousDiffAction: NavigateAction;
private toggleIgnoreTrimWhitespaceAction: ToggleIgnoreTrimWhitespaceAction;
private _configurationListener: IDisposable;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IInstantiationService instantiationService: IInstantiationService,
@IStorageService storageService: IStorageService,
@ITextResourceConfigurationService configurationService: ITextResourceConfigurationService,
@IConfigurationService private readonly _actualConfigurationService: IConfigurationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IThemeService themeService: IThemeService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@ITextFileService textFileService: ITextFileService
) {
super(TextDiffEditor.ID, telemetryService, instantiationService, storageService, configurationService, themeService, textFileService, editorGroupService);
this._configurationListener = this._actualConfigurationService.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('diffEditor.ignoreTrimWhitespace')) {
this.updateIgnoreTrimWhitespaceAction();
}
});
}
public getTitle(): string {
......@@ -72,6 +83,8 @@ export class TextDiffEditor extends BaseTextEditor {
// Actions
this.nextDiffAction = new NavigateAction(this, true);
this.previousDiffAction = new NavigateAction(this, false);
this.toggleIgnoreTrimWhitespaceAction = new ToggleIgnoreTrimWhitespaceAction(this._actualConfigurationService);
this.updateIgnoreTrimWhitespaceAction();
// Support navigation within the diff editor by overriding the editor service within
const delegatingEditorService = this.instantiationService.createInstance(DelegatingWorkbenchEditorService);
......@@ -163,6 +176,7 @@ export class TextDiffEditor extends BaseTextEditor {
this.nextDiffAction.updateEnablement();
this.previousDiffAction.updateEnablement();
});
this.updateIgnoreTrimWhitespaceAction();
}, error => {
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
......@@ -176,6 +190,13 @@ export class TextDiffEditor extends BaseTextEditor {
});
}
private updateIgnoreTrimWhitespaceAction(): void {
const ignoreTrimWhitespace = this.configurationService.getValue<boolean>(this.getResource(), 'diffEditor.ignoreTrimWhitespace');
if (this.toggleIgnoreTrimWhitespaceAction) {
this.toggleIgnoreTrimWhitespaceAction.updateClassName(ignoreTrimWhitespace);
}
}
private openAsBinary(input: EditorInput, options: EditorOptions): boolean {
if (input instanceof DiffEditorInput) {
const originalInput = input.originalInput;
......@@ -273,6 +294,7 @@ export class TextDiffEditor extends BaseTextEditor {
public getActions(): IAction[] {
return [
this.toggleIgnoreTrimWhitespaceAction,
this.previousDiffAction,
this.nextDiffAction
];
......@@ -303,6 +325,8 @@ export class TextDiffEditor extends BaseTextEditor {
this.diffNavigator.dispose();
}
this._configurationListener.dispose();
super.dispose();
}
}
......@@ -340,6 +364,29 @@ class NavigateAction extends Action {
}
}
class ToggleIgnoreTrimWhitespaceAction extends Action {
static ID = 'workbench.action.compareEditor.toggleIgnoreTrimWhitespace';
private _isChecked: boolean;
constructor(
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
super(ToggleIgnoreTrimWhitespaceAction.ID);
this.label = nls.localize('toggleIgnoreTrimWhitespace.label', "Ignore Trim Whitespace");
}
public updateClassName(ignoreTrimWhitespace: boolean): void {
this._isChecked = ignoreTrimWhitespace;
this.class = `textdiff-editor-action toggleIgnoreTrimWhitespace${this._isChecked ? ' is-checked' : ''}`;
}
public run(): TPromise<any> {
this._configurationService.updateValue(`diffEditor.ignoreTrimWhitespace`, !this._isChecked);
return null;
}
}
class ToggleEditorModeAction extends Action {
private static readonly ID = 'toggle.diff.editorMode';
private static readonly INLINE_LABEL = nls.localize('inlineDiffLabel', "Switch to Inline View");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册