Skip to content

Commit eec239d

Browse files
authored
1 parent f632275 commit eec239d

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IContentSizeChangedEvent } from 'vs/editor/common/editorCommon';
1515
import { localize } from 'vs/nls';
1616
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1717
import { DiffEditorOptions } from './diffEditorOptions';
18+
import { IObservable, IReader } from 'vs/base/common/observable';
1819

1920
export class DiffEditorEditors extends Disposable {
2021
public readonly modified: CodeEditorWidget;
@@ -29,6 +30,7 @@ export class DiffEditorEditors extends Disposable {
2930
private readonly _options: DiffEditorOptions,
3031
codeEditorWidgetOptions: IDiffCodeEditorWidgetOptions,
3132
private readonly _createInnerEditor: (instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorOptions>, editorWidgetOptions: ICodeEditorWidgetOptions) => CodeEditorWidget,
33+
private readonly _modifiedReadOnlyOverride: IObservable<boolean>,
3234
@IInstantiationService private readonly _instantiationService: IInstantiationService
3335
) {
3436
super();
@@ -47,19 +49,21 @@ export class DiffEditorEditors extends Disposable {
4749
}, (reader, changeSummary) => {
4850
_options.editorOptions.read(reader);
4951

50-
this.modified.updateOptions(this._adjustOptionsForRightHandSide(changeSummary));
51-
this.original.updateOptions(this._adjustOptionsForLeftHandSide(changeSummary));
52+
this.modified.updateOptions(this._adjustOptionsForRightHandSide(reader, changeSummary));
53+
this.original.updateOptions(this._adjustOptionsForLeftHandSide(reader, changeSummary));
5254
}));
5355
}
5456

5557
private _createLeftHandSideEditor(options: Readonly<IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget {
56-
const editor = this._constructInnerEditor(this._instantiationService, this.originalEditorElement, this._adjustOptionsForLeftHandSide(options), codeEditorWidgetOptions);
58+
const leftHandSideOptions = this._adjustOptionsForLeftHandSide(undefined, options);
59+
const editor = this._constructInnerEditor(this._instantiationService, this.originalEditorElement, leftHandSideOptions, codeEditorWidgetOptions);
5760
editor.setContextValue('isInDiffLeftEditor', true);
5861
return editor;
5962
}
6063

6164
private _createRightHandSideEditor(options: Readonly<IDiffEditorConstructionOptions>, codeEditorWidgetOptions: ICodeEditorWidgetOptions): CodeEditorWidget {
62-
const editor = this._constructInnerEditor(this._instantiationService, this.modifiedEditorElement, this._adjustOptionsForRightHandSide(options), codeEditorWidgetOptions);
65+
const rightHandSideOptions = this._adjustOptionsForRightHandSide(undefined, options);
66+
const editor = this._constructInnerEditor(this._instantiationService, this.modifiedEditorElement, rightHandSideOptions, codeEditorWidgetOptions);
6367
editor.setContextValue('isInDiffRightEditor', true);
6468
return editor;
6569
}
@@ -81,7 +85,7 @@ export class DiffEditorEditors extends Disposable {
8185
return editor;
8286
}
8387

84-
private _adjustOptionsForLeftHandSide(changedOptions: Readonly<IDiffEditorConstructionOptions>): IEditorConstructionOptions {
88+
private _adjustOptionsForLeftHandSide(_reader: IReader | undefined, changedOptions: Readonly<IDiffEditorConstructionOptions>): IEditorConstructionOptions {
8589
const result = this._adjustOptionsForSubEditor(changedOptions);
8690
if (!this._options.renderSideBySide.get()) {
8791
// never wrap hidden editor
@@ -101,7 +105,7 @@ export class DiffEditorEditors extends Disposable {
101105
return result;
102106
}
103107

104-
private _adjustOptionsForRightHandSide(changedOptions: Readonly<IDiffEditorConstructionOptions>): IEditorConstructionOptions {
108+
private _adjustOptionsForRightHandSide(reader: IReader | undefined, changedOptions: Readonly<IDiffEditorConstructionOptions>): IEditorConstructionOptions {
105109
const result = this._adjustOptionsForSubEditor(changedOptions);
106110
if (changedOptions.modifiedAriaLabel) {
107111
result.ariaLabel = changedOptions.modifiedAriaLabel;
@@ -111,6 +115,7 @@ export class DiffEditorEditors extends Disposable {
111115
result.revealHorizontalRightPadding = EditorOptions.revealHorizontalRightPadding.defaultValue + OverviewRulerPart.ENTIRE_DIFF_OVERVIEW_WIDTH;
112116
result.scrollbar!.verticalHasArrows = false;
113117
result.extraEditorClassName = 'modified-in-monaco-diff-editor';
118+
result.readOnly = this._modifiedReadOnlyOverride.read(reader) || this._options.editorOptions.get().readOnly;
114119
return result;
115120
}
116121

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
9696
this._rootSizeObserver = this._register(new ObservableElementSizeObserver(this.elements.root, options.dimension));
9797
this._rootSizeObserver.setAutomaticLayout(options.automaticLayout ?? false);
9898

99+
const reviewPaneObservable = observableValue<undefined | DiffReview2>('reviewPane', undefined);
99100
this._editors = this._register(this._instantiationService.createInstance(
100101
DiffEditorEditors,
101102
this.elements.original,
102103
this.elements.modified,
103104
this._options,
104105
codeEditorWidgetOptions,
105106
(i, c, o, o2) => this._createInnerEditor(i, c, o, o2),
107+
reviewPaneObservable.map((r, reader) => r?.isVisible.read(reader) ?? false),
106108
));
107109

108110
this._sash = derivedWithStore('sash', (reader, store) => {
@@ -159,6 +161,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
159161
this.elements.root.appendChild(this._reviewPane.domNode.domNode);
160162
this.elements.root.appendChild(this._reviewPane.shadow.domNode);
161163
this.elements.root.appendChild(this._reviewPane.actionBarContainer.domNode);
164+
reviewPaneObservable.set(this._reviewPane, undefined);
162165

163166
this._createDiffEditorContributions();
164167

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Action } from 'vs/base/common/actions';
1111
import { Codicon } from 'vs/base/common/codicons';
1212
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
1313
import { Disposable } from 'vs/base/common/lifecycle';
14+
import { IObservable, observableValue } from 'vs/base/common/observable';
1415
import { ThemeIcon } from 'vs/base/common/themables';
1516
import { Constants } from 'vs/base/common/uint';
1617
import { applyFontInfo } from 'vs/editor/browser/config/domFontInfo';
@@ -85,7 +86,7 @@ export class DiffReview2 extends Disposable {
8586
private static _ttPolicy = DiffReview._ttPolicy; // TODO inline once DiffReview is deprecated.
8687

8788
private readonly _diffEditor: DiffEditorWidget2;
88-
private _isVisible: boolean;
89+
private get _isVisible() { return this._isVisibleObs.get(); }
8990
public readonly shadow: FastDomNode<HTMLElement>;
9091
private readonly _actionBar: ActionBar;
9192
public readonly actionBarContainer: FastDomNode<HTMLElement>;
@@ -95,6 +96,10 @@ export class DiffReview2 extends Disposable {
9596
private _diffs: Diff[];
9697
private _currentDiff: Diff | null;
9798

99+
private readonly _isVisibleObs = observableValue('isVisible', false);
100+
101+
public readonly isVisible: IObservable<boolean> = this._isVisibleObs;
102+
98103
constructor(
99104
diffEditor: DiffEditorWidget2,
100105
@ILanguageService private readonly _languageService: ILanguageService,
@@ -103,7 +108,6 @@ export class DiffReview2 extends Disposable {
103108
) {
104109
super();
105110
this._diffEditor = diffEditor;
106-
this._isVisible = false;
107111

108112
this.shadow = createFastDomNode(document.createElement('div'));
109113
this.shadow.setClassName('diff-review-shadow');
@@ -215,7 +219,7 @@ export class DiffReview2 extends Disposable {
215219
const entries = this._diffs[index].entries;
216220
this._diffEditor.setPosition(new Position(entries[0].modifiedLineStart, 1));
217221
this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: Constants.MAX_SAFE_SMALL_INTEGER, endLineNumber: entries[entries.length - 1].modifiedLineEnd });
218-
this._isVisible = true;
222+
this._isVisibleObs.set(true, undefined);
219223
this.layout();
220224
this._render();
221225
this._goToRow(this._getPrevRow(), 'previous');
@@ -250,7 +254,7 @@ export class DiffReview2 extends Disposable {
250254
const entries = this._diffs[index].entries;
251255
this._diffEditor.setPosition(new Position(entries[0].modifiedLineStart, 1));
252256
this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: Constants.MAX_SAFE_SMALL_INTEGER, endLineNumber: entries[entries.length - 1].modifiedLineEnd });
253-
this._isVisible = true;
257+
this._isVisibleObs.set(true, undefined);
254258
this.layout();
255259
this._render();
256260
this._goToRow(this._getNextRow(), 'next');
@@ -274,8 +278,7 @@ export class DiffReview2 extends Disposable {
274278
}
275279

276280
private hide(): void {
277-
this._isVisible = false;
278-
this._diffEditor.updateOptions({ readOnly: false });
281+
this._isVisibleObs.set(false, undefined);
279282
this._diffEditor.focus();
280283
this.layout();
281284
this._render();
@@ -331,10 +334,6 @@ export class DiffReview2 extends Disposable {
331334
this.scrollbar.scanDomNode();
332335
}
333336

334-
public isVisible(): boolean {
335-
return this._isVisible;
336-
}
337-
338337
private _width: number = 0;
339338
private _top: number = 0;
340339
private _height: number = 0;
@@ -564,7 +563,6 @@ export class DiffReview2 extends Disposable {
564563
return;
565564
}
566565

567-
this._diffEditor.updateOptions({ readOnly: true });
568566
const diffIndex = this._findDiffIndex(this._diffEditor.getPosition()!);
569567

570568
if (this._diffs[diffIndex] === this._currentDiff) {

0 commit comments

Comments
 (0)