From a4db7309afdda49c4fda178ed9f0d6657bca5115 Mon Sep 17 00:00:00 2001 From: Kim Santiago <31145923+kisantia@users.noreply.github.com> Date: Wed, 14 Dec 2022 17:24:10 -0800 Subject: [PATCH] Fix schema compare not always showing diff color highlighting (#21413) * Fix schema compare not always showing diff color highlighting * move helper functions into diffEditorWidget.ts --- src/sql/editor/browser/diffEditorHelper.ts | 35 -------- .../editor/browser/widget/diffEditorWidget.ts | 79 ++++++++++++++++--- 2 files changed, 69 insertions(+), 45 deletions(-) delete mode 100644 src/sql/editor/browser/diffEditorHelper.ts diff --git a/src/sql/editor/browser/diffEditorHelper.ts b/src/sql/editor/browser/diffEditorHelper.ts deleted file mode 100644 index 9d4e6dbbde..0000000000 --- a/src/sql/editor/browser/diffEditorHelper.ts +++ /dev/null @@ -1,35 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the Source EULA. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { ILineChange } from 'vs/editor/common/diff/diffComputer'; - -/** - * Swaps the original and modified line changes - * @param lineChanges The line changes to be reversed - */ -export function reverseLineChanges(lineChanges: ILineChange[]): 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 0af4fb37b9..5ab48860e4 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -46,7 +46,6 @@ import { EditorExtensionsRegistry, IDiffEditorContributionDescription } from 'vs import { onUnexpectedError } from 'vs/base/common/errors'; import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress'; import { ElementSizeObserver } from 'vs/editor/browser/config/elementSizeObserver'; -import { reverseLineChanges } from 'sql/editor/browser/diffEditorHelper'; // {{SQL CARBON EDIT}} import { Codicon } from 'vs/base/common/codicons'; import { MOUSE_CURSOR_TEXT_CSS_CLASS_NAME } from 'vs/base/browser/ui/mouseCursor/mouseCursor'; import { IViewLineTokens } from 'vs/editor/common/tokens/lineTokens'; @@ -1397,19 +1396,17 @@ abstract class DiffEditorWidgetStyle extends Disposable { }); const zones = this._getViewZones(lineChanges, originalWhitespaces, modifiedWhitespaces, renderIndicators); - // {{SQL CARBON EDIT}} - if (reverse) { - lineChanges = reverseLineChanges(lineChanges); - [originalEditor, modifiedEditor] = [modifiedEditor, originalEditor]; - } - - // {{SQL CARBON EDIT}} // Get decorations & overview ruler zones let originalDecorations = this._getOriginalEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators); let modifiedDecorations = this._getModifiedEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators); - // {{SQL CARBON EDIT}} + + // {{SQL CARBON EDIT}} - reverse decorations if (reverse) { - [originalDecorations, modifiedDecorations] = [modifiedDecorations, originalDecorations]; + reverseDecorations(originalDecorations.decorations); + reverseDecorations(modifiedDecorations.decorations); + + originalDecorations.overviewZones = setOverviewZonesColor(originalDecorations.overviewZones, String(this._insertColor)); + modifiedDecorations.overviewZones = setOverviewZonesColor(modifiedDecorations.overviewZones, String(this._removeColor)); } return { @@ -1799,6 +1796,68 @@ const DECORATIONS = { }; +// {{SQL CARBON EDIT}} - helper function for reversing colors for schema compare +/** + * Reverses the decorations of the given array of decorations, so that deletes and inserts are swapped + * @param decorations + */ +function reverseDecorations(decorations: IModelDeltaDecoration[]): void { + for (let dec of decorations) { + switch (dec.options.description) { + case 'diff-editor-char-delete': { + dec.options = DECORATIONS.charInsert; + break; + } + case 'diff-editor-char-delete-whole-line': { + dec.options = DECORATIONS.charInsertWholeLine; + break; + } + case 'diff-editor-char-insert': { + dec.options = DECORATIONS.charDelete; + break; + } + case 'diff-editor-char-insert-whole-line': { + dec.options = DECORATIONS.charDeleteWholeLine; + break; + } + case 'diff-editor-line-insert': { + dec.options = DECORATIONS.lineDelete; + break; + } + case 'diff-editor-line-insert-with-sign': { + dec.options = DECORATIONS.lineDeleteWithSign; + break; + } + case 'diff-editor-line-delete': { + dec.options = DECORATIONS.lineInsert; + break; + } + case 'diff-editor-line-delete-with-sign': { + dec.options = DECORATIONS.lineInsertWithSign; + break; + } + } + } +} + +// {{SQL CARBON EDIT}} - helper function for reversing colors for schema compare +/** + * Sets the overview zones to the provided color + * @param zones Array of zones to update + * @param color Color to set the overview zones to + * @returns + */ +function setOverviewZonesColor(zones: OverviewRulerZone[], color: string): OverviewRulerZone[] { + let reversedZones = []; + + for (const zone of zones) { + // There color of an overview zone is readonly, so create a new one with the updated color + reversedZones.push(new OverviewRulerZone(zone.startLineNumber, zone.endLineNumber, zone.heightInLines, color)); + } + + return reversedZones; +} + class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IVerticalSashLayoutProvider { static readonly MINIMUM_EDITOR_WIDTH = 100;