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
This commit is contained in:
Kim Santiago
2022-12-14 17:24:10 -08:00
committed by GitHub
parent 234c3debaa
commit a4db7309af
2 changed files with 69 additions and 45 deletions

View File

@@ -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;
}

View File

@@ -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;