diff --git a/src/sql/editor/browser/diffEditorHelper.ts b/src/sql/editor/browser/diffEditorHelper.ts new file mode 100644 index 0000000000..6cf3088346 --- /dev/null +++ b/src/sql/editor/browser/diffEditorHelper.ts @@ -0,0 +1,35 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as editorCommon from 'vs/editor/common/editorCommon'; + +/** + * Swaps the original and modified line changes + * @param lineChanges The line changes to be reversed + */ +export function reverseLineChanges(lineChanges: editorCommon.ILineChange[]): editorCommon.ILineChange[] { + let reversedLineChanges = lineChanges.map(linechange => { + return { + modifiedStartLineNumber: linechange.originalStartLineNumber, + modifiedEndLineNumber: linechange.originalEndLineNumber, + originalStartLineNumber: linechange.modifiedStartLineNumber, + originalEndLineNumber: linechange.modifiedEndLineNumber, + charChanges: (linechange.charChanges) ? + linechange.charChanges.map(charchange => { + return { + originalStartColumn: charchange.modifiedStartColumn, + originalEndColumn: charchange.modifiedEndColumn, + modifiedStartColumn: charchange.originalStartColumn, + modifiedEndColumn: charchange.originalEndColumn, + modifiedStartLineNumber: charchange.originalStartLineNumber, + modifiedEndLineNumber: charchange.originalEndLineNumber, + originalStartLineNumber: charchange.modifiedStartLineNumber, + originalEndLineNumber: charchange.modifiedEndLineNumber, + }; + }) : undefined + }; + }); + return reversedLineChanges; + } diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index 37a767aa6f..0344aa181b 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -40,6 +40,8 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle import { INotificationService } from 'vs/platform/notification/common/notification'; import { defaultInsertColor, defaultRemoveColor, diffBorder, diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, scrollbarShadow } from 'vs/platform/theme/common/colorRegistry'; import { ITheme, IThemeService, getThemeTypeSelector, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; +// {{SQL CARBON EDIT}} +import { reverseLineChanges } from 'sql/editor/browser/DiffEditorHelper'; interface IEditorDiffDecorations { decorations: IModelDeltaDecoration[]; @@ -61,7 +63,8 @@ interface IEditorsZones { } interface IDiffEditorWidgetStyle { - getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones; + // {{SQL CARBON EDIT}} + getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, reverse?: boolean): IEditorsDiffDecorationsWithZones; setEnableSplitViewResizing(enableSplitViewResizing: boolean): void; applyColors(theme: ITheme): boolean; layout(): number; @@ -193,6 +196,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE private readonly _notificationService: INotificationService; private readonly _reviewPane: DiffReview; + // {{SQL CARBON EDIT}} + private _options: editorOptions.IDiffEditorOptions; constructor( domElement: HTMLElement, @@ -212,6 +217,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE this._contextKeyService.createKey('isInDiffEditor', true); this._themeService = themeService; this._notificationService = notificationService; + // {{SQL CARBON EDIT}} + this._options = options; this.id = (++DIFF_EDITOR_ID); @@ -927,7 +934,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE let foreignOriginal = this._originalEditorState.getForeignViewZones(this.originalEditor.getWhitespaces()); let foreignModified = this._modifiedEditorState.getForeignViewZones(this.modifiedEditor.getWhitespaces()); - let diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._ignoreTrimWhitespace, this._renderIndicators, foreignOriginal, foreignModified, this.originalEditor, this.modifiedEditor); + // {{SQL CARBON EDIT}} + let diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._ignoreTrimWhitespace, this._renderIndicators, foreignOriginal, foreignModified, this.originalEditor, this.modifiedEditor, this._options.reverse); try { this._currentlyChangingViewZones = true; @@ -1203,7 +1211,8 @@ abstract class DiffEditorWidgetStyle extends Disposable implements IDiffEditorWi return hasChanges; } - public getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor): IEditorsDiffDecorationsWithZones { + // {{SQL CARBON EDIT}} + public getEditorsDiffDecorations(lineChanges: editorCommon.ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[], originalEditor: editorBrowser.ICodeEditor, modifiedEditor: editorBrowser.ICodeEditor, reverse?: boolean): IEditorsDiffDecorationsWithZones { // Get view zones modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => { return a.afterLineNumber - b.afterLineNumber; @@ -1213,10 +1222,21 @@ abstract class DiffEditorWidgetStyle extends Disposable implements IDiffEditorWi }); let zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, originalEditor, modifiedEditor, renderIndicators); + // {{SQL CARBON EDIT}} + if (reverse) { + lineChanges = reverseLineChanges(lineChanges); + [originalEditor, modifiedEditor] = [modifiedEditor, originalEditor]; + } + // Get decorations & overview ruler zones let originalDecorations = this._getOriginalEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor); let modifiedDecorations = this._getModifiedEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor); + // {{SQL CARBON EDIT}} + if (reverse) { + [originalDecorations, modifiedDecorations] = [modifiedDecorations, originalDecorations]; + } + return { original: { decorations: originalDecorations.decorations, diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 61ec6d7e9a..0569682f4a 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -744,6 +744,12 @@ export interface IDiffEditorOptions extends IEditorOptions { * Defaults to false. */ originalEditable?: boolean; + + // {{SQL CARBON EDIT}} + /** + * Adding option to reverse coloring in diff editor + */ + reverse?: boolean; } export const enum RenderMinimap { diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index bf9b483893..e9fb65166f 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3080,6 +3080,10 @@ declare namespace monaco.editor { * Defaults to false. */ originalEditable?: boolean; + /** + * Adding option to reverse coloring in diff editor + */ + reverse?: boolean; } export enum RenderMinimap { diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index c61d5f04d7..a6d9104026 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -42,6 +42,8 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { private diffNavigator: DiffNavigator; private diffNavigatorDisposables: IDisposable[] = []; + // {{SQL CARBON EDIT}} + private reverseColor: boolean; constructor( @ITelemetryService telemetryService: ITelemetryService, @@ -69,7 +71,17 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { return nls.localize('textDiffEditor', "Text Diff Editor"); } + // {{SQL CARBON EDIT}} + reverseColoring(): void { + this.reverseColor = true; + } + createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor { + // {{SQL CARBON EDIT}} + if (this.reverseColor) { + (configuration as IDiffEditorOptions).reverse = true; + } + return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration); }