mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 11:01:37 -05:00
Add reverse color option to text diff editor (#4826)
* Add reverse color option to text diff editor
This commit is contained in:
35
src/sql/editor/browser/diffEditorHelper.ts
Normal file
35
src/sql/editor/browser/diffEditorHelper.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
@@ -40,6 +40,8 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
|
|||||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||||
import { defaultInsertColor, defaultRemoveColor, diffBorder, diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, scrollbarShadow } from 'vs/platform/theme/common/colorRegistry';
|
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';
|
import { ITheme, IThemeService, getThemeTypeSelector, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
import { reverseLineChanges } from 'sql/editor/browser/DiffEditorHelper';
|
||||||
|
|
||||||
interface IEditorDiffDecorations {
|
interface IEditorDiffDecorations {
|
||||||
decorations: IModelDeltaDecoration[];
|
decorations: IModelDeltaDecoration[];
|
||||||
@@ -61,7 +63,8 @@ interface IEditorsZones {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IDiffEditorWidgetStyle {
|
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;
|
setEnableSplitViewResizing(enableSplitViewResizing: boolean): void;
|
||||||
applyColors(theme: ITheme): boolean;
|
applyColors(theme: ITheme): boolean;
|
||||||
layout(): number;
|
layout(): number;
|
||||||
@@ -193,6 +196,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
|
|||||||
private readonly _notificationService: INotificationService;
|
private readonly _notificationService: INotificationService;
|
||||||
|
|
||||||
private readonly _reviewPane: DiffReview;
|
private readonly _reviewPane: DiffReview;
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
private _options: editorOptions.IDiffEditorOptions;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
domElement: HTMLElement,
|
domElement: HTMLElement,
|
||||||
@@ -212,6 +217,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
|
|||||||
this._contextKeyService.createKey('isInDiffEditor', true);
|
this._contextKeyService.createKey('isInDiffEditor', true);
|
||||||
this._themeService = themeService;
|
this._themeService = themeService;
|
||||||
this._notificationService = notificationService;
|
this._notificationService = notificationService;
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
this._options = options;
|
||||||
|
|
||||||
this.id = (++DIFF_EDITOR_ID);
|
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 foreignOriginal = this._originalEditorState.getForeignViewZones(this.originalEditor.getWhitespaces());
|
||||||
let foreignModified = this._modifiedEditorState.getForeignViewZones(this.modifiedEditor.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 {
|
try {
|
||||||
this._currentlyChangingViewZones = true;
|
this._currentlyChangingViewZones = true;
|
||||||
@@ -1203,7 +1211,8 @@ abstract class DiffEditorWidgetStyle extends Disposable implements IDiffEditorWi
|
|||||||
return hasChanges;
|
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
|
// Get view zones
|
||||||
modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
|
modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
|
||||||
return a.afterLineNumber - b.afterLineNumber;
|
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);
|
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
|
// Get decorations & overview ruler zones
|
||||||
let originalDecorations = this._getOriginalEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
|
let originalDecorations = this._getOriginalEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
|
||||||
let modifiedDecorations = this._getModifiedEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
|
let modifiedDecorations = this._getModifiedEditorDecorations(lineChanges, ignoreTrimWhitespace, renderIndicators, originalEditor, modifiedEditor);
|
||||||
|
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
if (reverse) {
|
||||||
|
[originalDecorations, modifiedDecorations] = [modifiedDecorations, originalDecorations];
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
original: {
|
original: {
|
||||||
decorations: originalDecorations.decorations,
|
decorations: originalDecorations.decorations,
|
||||||
|
|||||||
@@ -744,6 +744,12 @@ export interface IDiffEditorOptions extends IEditorOptions {
|
|||||||
* Defaults to false.
|
* Defaults to false.
|
||||||
*/
|
*/
|
||||||
originalEditable?: boolean;
|
originalEditable?: boolean;
|
||||||
|
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
/**
|
||||||
|
* Adding option to reverse coloring in diff editor
|
||||||
|
*/
|
||||||
|
reverse?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum RenderMinimap {
|
export const enum RenderMinimap {
|
||||||
|
|||||||
4
src/vs/monaco.d.ts
vendored
4
src/vs/monaco.d.ts
vendored
@@ -3080,6 +3080,10 @@ declare namespace monaco.editor {
|
|||||||
* Defaults to false.
|
* Defaults to false.
|
||||||
*/
|
*/
|
||||||
originalEditable?: boolean;
|
originalEditable?: boolean;
|
||||||
|
/**
|
||||||
|
* Adding option to reverse coloring in diff editor
|
||||||
|
*/
|
||||||
|
reverse?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum RenderMinimap {
|
export enum RenderMinimap {
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
|
|||||||
|
|
||||||
private diffNavigator: DiffNavigator;
|
private diffNavigator: DiffNavigator;
|
||||||
private diffNavigatorDisposables: IDisposable[] = [];
|
private diffNavigatorDisposables: IDisposable[] = [];
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
private reverseColor: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ITelemetryService telemetryService: ITelemetryService,
|
@ITelemetryService telemetryService: ITelemetryService,
|
||||||
@@ -69,7 +71,17 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
|
|||||||
return nls.localize('textDiffEditor', "Text Diff Editor");
|
return nls.localize('textDiffEditor', "Text Diff Editor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
reverseColoring(): void {
|
||||||
|
this.reverseColor = true;
|
||||||
|
}
|
||||||
|
|
||||||
createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor {
|
createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor {
|
||||||
|
// {{SQL CARBON EDIT}}
|
||||||
|
if (this.reverseColor) {
|
||||||
|
(configuration as IDiffEditorOptions).reverse = true;
|
||||||
|
}
|
||||||
|
|
||||||
return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration);
|
return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user