Skip to content

Commit 0a3ca02

Browse files
authored
Add config for disable arrows in diff (microsoft#153199)
1 parent 64b74d9 commit 0a3ca02

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
260260
this._options = validateDiffEditorOptions(options, {
261261
enableSplitViewResizing: true,
262262
renderSideBySide: true,
263+
renderMarginRevertIcon: true,
263264
maxComputationTime: 5000,
264265
maxFileSize: 50,
265266
ignoreTrimWhitespace: true,
@@ -646,7 +647,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
646647
range,
647648
text: '',
648649
}]);
649-
} else if (change.modifiedEndLineNumber === 0 && originalContent) {
650+
} else if (change.modifiedEndLineNumber === 0 && originalContent !== null) {
650651
// Delete change.
651652
// To revert: insert the old content and a linebreak.
652653

@@ -745,7 +746,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
745746
const changed = changedDiffEditorOptions(this._options, newOptions);
746747
this._options = newOptions;
747748

748-
const beginUpdateDecorations = (changed.ignoreTrimWhitespace || changed.renderIndicators);
749+
const beginUpdateDecorations = (changed.ignoreTrimWhitespace || changed.renderIndicators || changed.renderMarginRevertIcon);
749750
const beginUpdateDecorationsSoon = (this._isVisible && (changed.maxComputationTime || changed.maxFileSize));
750751

751752
if (beginUpdateDecorations) {
@@ -1143,7 +1144,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
11431144
const foreignOriginal = this._originalEditorState.getForeignViewZones(this._originalEditor.getWhitespaces());
11441145
const foreignModified = this._modifiedEditorState.getForeignViewZones(this._modifiedEditor.getWhitespaces());
11451146

1146-
const diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._options.ignoreTrimWhitespace, this._options.renderIndicators, foreignOriginal, foreignModified);
1147+
const diffDecorations = this._strategy.getEditorsDiffDecorations(lineChanges, this._options.ignoreTrimWhitespace, this._options.renderIndicators, this._options.renderMarginRevertIcon, foreignOriginal, foreignModified);
11471148

11481149
try {
11491150
this._currentlyChangingViewZones = true;
@@ -1459,7 +1460,7 @@ abstract class DiffEditorWidgetStyle extends Disposable {
14591460
return hasChanges;
14601461
}
14611462

1462-
public getEditorsDiffDecorations(lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[]): IEditorsDiffDecorationsWithZones {
1463+
public getEditorsDiffDecorations(lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean, originalWhitespaces: IEditorWhitespace[], modifiedWhitespaces: IEditorWhitespace[]): IEditorsDiffDecorationsWithZones {
14631464
// Get view zones
14641465
modifiedWhitespaces = modifiedWhitespaces.sort((a, b) => {
14651466
return a.afterLineNumber - b.afterLineNumber;
@@ -1471,7 +1472,7 @@ abstract class DiffEditorWidgetStyle extends Disposable {
14711472

14721473
// Get decorations & overview ruler zones
14731474
const originalDecorations = this._getOriginalEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators);
1474-
const modifiedDecorations = this._getModifiedEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators);
1475+
const modifiedDecorations = this._getModifiedEditorDecorations(zones, lineChanges, ignoreTrimWhitespace, renderIndicators, renderMarginRevertIcon);
14751476

14761477
return {
14771478
original: {
@@ -1489,7 +1490,7 @@ abstract class DiffEditorWidgetStyle extends Disposable {
14891490

14901491
protected abstract _getViewZones(lineChanges: ILineChange[], originalForeignVZ: IEditorWhitespace[], modifiedForeignVZ: IEditorWhitespace[], renderIndicators: boolean): IEditorsZones;
14911492
protected abstract _getOriginalEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations;
1492-
protected abstract _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations;
1493+
protected abstract _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations;
14931494

14941495
public abstract setEnableSplitViewResizing(enableSplitViewResizing: boolean): void;
14951496
public abstract layout(): number;
@@ -2031,7 +2032,7 @@ class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IVerti
20312032
return result;
20322033
}
20332034

2034-
protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations {
2035+
protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations {
20352036
const modifiedEditor = this._dataSource.getModifiedEditor();
20362037
const overviewZoneColor = String(this._insertColor);
20372038

@@ -2046,15 +2047,17 @@ class DiffEditorWidgetSideBySide extends DiffEditorWidgetStyle implements IVerti
20462047
for (const lineChange of lineChanges) {
20472048

20482049
// Arrows for reverting changes.
2049-
if (lineChange.modifiedEndLineNumber > 0) {
2050-
result.decorations.push({
2051-
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedStartLineNumber, 1),
2052-
options: DECORATIONS.arrowRevertChange
2053-
});
2054-
} else {
2055-
const viewZone = zones.modified.find(z => z.afterLineNumber === lineChange.modifiedStartLineNumber);
2056-
if (viewZone) {
2057-
viewZone.marginDomNode = createViewZoneMarginArrow();
2050+
if (renderMarginRevertIcon) {
2051+
if (lineChange.modifiedEndLineNumber > 0) {
2052+
result.decorations.push({
2053+
range: new Range(lineChange.modifiedStartLineNumber, 1, lineChange.modifiedStartLineNumber, 1),
2054+
options: DECORATIONS.arrowRevertChange
2055+
});
2056+
} else {
2057+
const viewZone = zones.modified.find(z => z.afterLineNumber === lineChange.modifiedStartLineNumber);
2058+
if (viewZone) {
2059+
viewZone.marginDomNode = createViewZoneMarginArrow();
2060+
}
20582061
}
20592062
}
20602063

@@ -2222,7 +2225,7 @@ class DiffEditorWidgetInline extends DiffEditorWidgetStyle {
22222225
return result;
22232226
}
22242227

2225-
protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean): IEditorDiffDecorations {
2228+
protected _getModifiedEditorDecorations(zones: IEditorsZones, lineChanges: ILineChange[], ignoreTrimWhitespace: boolean, renderIndicators: boolean, renderMarginRevertIcon: boolean): IEditorDiffDecorations {
22262229
const modifiedEditor = this._dataSource.getModifiedEditor();
22272230
const overviewZoneColor = String(this._insertColor);
22282231

@@ -2641,6 +2644,7 @@ function validateDiffEditorOptions(options: Readonly<IDiffEditorOptions>, defaul
26412644
return {
26422645
enableSplitViewResizing: validateBooleanOption(options.enableSplitViewResizing, defaults.enableSplitViewResizing),
26432646
renderSideBySide: validateBooleanOption(options.renderSideBySide, defaults.renderSideBySide),
2647+
renderMarginRevertIcon: validateBooleanOption(options.renderMarginRevertIcon, defaults.renderMarginRevertIcon),
26442648
maxComputationTime: clampedInt(options.maxComputationTime, defaults.maxComputationTime, 0, Constants.MAX_SAFE_SMALL_INTEGER),
26452649
maxFileSize: clampedInt(options.maxFileSize, defaults.maxFileSize, 0, Constants.MAX_SAFE_SMALL_INTEGER),
26462650
ignoreTrimWhitespace: validateBooleanOption(options.ignoreTrimWhitespace, defaults.ignoreTrimWhitespace),
@@ -2656,6 +2660,7 @@ function changedDiffEditorOptions(a: ValidDiffEditorBaseOptions, b: ValidDiffEdi
26562660
return {
26572661
enableSplitViewResizing: (a.enableSplitViewResizing !== b.enableSplitViewResizing),
26582662
renderSideBySide: (a.renderSideBySide !== b.renderSideBySide),
2663+
renderMarginRevertIcon: (a.renderMarginRevertIcon !== b.renderMarginRevertIcon),
26592664
maxComputationTime: (a.maxComputationTime !== b.maxComputationTime),
26602665
maxFileSize: (a.maxFileSize !== b.maxFileSize),
26612666
ignoreTrimWhitespace: (a.ignoreTrimWhitespace !== b.ignoreTrimWhitespace),

src/vs/editor/common/config/editorConfigurationSchema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ const editorConfiguration: IConfigurationNode = {
146146
default: true,
147147
description: nls.localize('sideBySide', "Controls whether the diff editor shows the diff side by side or inline.")
148148
},
149+
'diffEditor.renderMarginRevertIcon': {
150+
type: 'boolean',
151+
default: true,
152+
description: nls.localize('renderMarginRevertIcon', "When enabled, the diff editor shows arrows in its glyph margin to revert changes.")
153+
},
149154
'diffEditor.ignoreTrimWhitespace': {
150155
type: 'boolean',
151156
default: true,

src/vs/editor/common/config/editorOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ export interface IDiffEditorBaseOptions {
705705
* Defaults to true.
706706
*/
707707
renderIndicators?: boolean;
708+
/**
709+
* Shows icons in the glyph margin to revert changes.
710+
* Default to true.
711+
*/
712+
renderMarginRevertIcon?: boolean;
708713
/**
709714
* Original model should be editable?
710715
* Defaults to false.

src/vs/monaco.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,11 @@ declare namespace monaco.editor {
34583458
* Defaults to true.
34593459
*/
34603460
renderIndicators?: boolean;
3461+
/**
3462+
* Shows icons in the glyph margin to revert changes.
3463+
* Default to true.
3464+
*/
3465+
renderMarginRevertIcon?: boolean;
34613466
/**
34623467
* Original model should be editable?
34633468
* Defaults to false.

0 commit comments

Comments
 (0)