Skip to content

Commit d02797a

Browse files
authored
Merge pull request microsoft#185900 from microsoft/hediet/b/sporting-flamingo
Don't render revert arrows for readonly files
2 parents e4e3e14 + 9345328 commit d02797a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/vs/editor/browser/widget/diffEditorWidget2/diffEditorDecorations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class DiffEditorDecorations extends Disposable {
2121
private readonly _originalEditor: CodeEditorWidget,
2222
private readonly _modifiedEditor: CodeEditorWidget,
2323
private readonly _diffModel: IObservable<DiffModel | undefined>,
24-
private readonly _renderSideBySide: IObservable<boolean>,
24+
private readonly _shouldRenderRevertArrows: IObservable<boolean>,
2525
) {
2626
super();
2727

@@ -64,7 +64,7 @@ export class DiffEditorDecorations extends Disposable {
6464
modifiedDecorations.push({ range: i.modifiedRange, options: i.modifiedRange.isEmpty() ? diffAddDecorationEmpty : diffAddDecoration });
6565
}
6666

67-
if (!m.lineRangeMapping.modifiedRange.isEmpty && this._renderSideBySide.read(reader) && !currentMove) {
67+
if (!m.lineRangeMapping.modifiedRange.isEmpty && this._shouldRenderRevertArrows.read(reader) && !currentMove) {
6868
modifiedDecorations.push({ range: Range.fromPositions(new Position(m.lineRangeMapping.modifiedRange.startLineNumber, 1)), options: arrowRevertChange });
6969
}
7070
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { OverviewRulerPart } from 'vs/editor/browser/widget/diffEditorWidget2/ov
2929
import { UnchangedRangesFeature } from 'vs/editor/browser/widget/diffEditorWidget2/unchangedRanges';
3030
import { ObservableElementSizeObserver, applyStyle, deepMerge, readHotReloadableExport } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
3131
import { WorkerBasedDocumentDiffProvider } from 'vs/editor/browser/widget/workerBasedDocumentDiffProvider';
32-
import { EditorOptions, IDiffEditorOptions, IEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
32+
import { EditorOption, EditorOptions, IDiffEditorOptions, IEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
3333
import { IDimension } from 'vs/editor/common/core/dimension';
3434
import { Position } from 'vs/editor/common/core/position';
3535
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer';
@@ -87,7 +87,19 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
8787
private readonly _boundarySashes = observableValue<IBoundarySashes | undefined>('boundarySashes', undefined);
8888
private readonly _renderOverviewRuler = derived('renderOverviewRuler', reader => this._options.read(reader).renderOverviewRuler);
8989
private readonly _renderSideBySide = derived('renderSideBySide', reader => this._options.read(reader).renderSideBySide);
90-
90+
private readonly _shouldRenderRevertArrows = derived('shouldRenderRevertArrows', (reader) => {
91+
if (!this._options.read(reader).renderMarginRevertIcon) {
92+
return false;
93+
}
94+
if (!this._renderSideBySide.read(reader)) {
95+
return false;
96+
}
97+
this._options.read(reader); // TODO@hediet editor options should be revisited. _options might just get partial updates.
98+
if (this._modifiedEditor.getOption(EditorOption.readOnly)) {
99+
return false;
100+
}
101+
return true;
102+
});
91103
private unchangedRangesFeature!: UnchangedRangesFeature;
92104

93105
private readonly _reviewPane: DiffReview2;
@@ -154,7 +166,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
154166

155167
this._register(autorunWithStore2('decorations', (reader, store) => {
156168
store.add(new (readHotReloadableExport(DiffEditorDecorations, reader))(
157-
this._originalEditor, this._modifiedEditor, this._diffModel, this._renderSideBySide,
169+
this._originalEditor, this._modifiedEditor, this._diffModel, this._shouldRenderRevertArrows,
158170
));
159171
}));
160172

@@ -164,6 +176,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
164176
this._modifiedEditor,
165177
this._diffModel,
166178
this._renderSideBySide,
179+
this._shouldRenderRevertArrows,
167180
this,
168181
() => this.unchangedRangesFeature.isUpdatingViewZones,
169182
));

src/vs/editor/browser/widget/diffEditorWidget2/lineAlignment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ViewZoneManager extends Disposable {
5252
private readonly _modifiedEditor: CodeEditorWidget,
5353
private readonly _diffModel: IObservable<DiffModel | undefined>,
5454
private readonly _renderSideBySide: IObservable<boolean>,
55+
private readonly _shouldRenderRevertArrows: IObservable<boolean>,
5556
private readonly _diffEditorWidget: DiffEditorWidget2,
5657
private readonly _canIgnoreViewZoneUpdateEvent: () => boolean,
5758
@IClipboardService private readonly _clipboardService: IClipboardService,
@@ -264,7 +265,7 @@ export class ViewZoneManager extends Disposable {
264265
}
265266

266267
let marginDomNode: HTMLElement | undefined = undefined;
267-
if (a.diff && a.diff.modifiedRange.isEmpty && this._renderSideBySide.read(reader)) {
268+
if (a.diff && a.diff.modifiedRange.isEmpty && this._shouldRenderRevertArrows.read(reader)) {
268269
marginDomNode = createViewZoneMarginArrow();
269270
}
270271

0 commit comments

Comments
 (0)