Skip to content

Commit 73eb619

Browse files
authored
Disable sticky scroll in diff editor when collapse unmodified code is enabled (microsoft#185434)
1 parent c0347d0 commit 73eb619

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import { ViewZoneManager } from 'vs/editor/browser/widget/diffEditorWidget2/line
2525
import { MovedBlocksLinesPart } from 'vs/editor/browser/widget/diffEditorWidget2/movedBlocksLines';
2626
import { OverviewRulerPart } from 'vs/editor/browser/widget/diffEditorWidget2/overviewRulerPart';
2727
import { UnchangedRangesFeature } from 'vs/editor/browser/widget/diffEditorWidget2/unchangedRanges';
28-
import { ObservableElementSizeObserver, applyObservableDecorations } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
28+
import { ObservableElementSizeObserver, applyObservableDecorations, deepMerge } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
2929
import { WorkerBasedDocumentDiffProvider } from 'vs/editor/browser/widget/workerBasedDocumentDiffProvider';
30-
import { EditorOptions, IDiffEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
30+
import { EditorOptions, IDiffEditorOptions, IEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
3131
import { IDimension } from 'vs/editor/common/core/dimension';
3232
import { LineRange } from 'vs/editor/common/core/lineRange';
3333
import { Position } from 'vs/editor/common/core/position';
@@ -42,6 +42,7 @@ import { DelegatingEditor } from './delegatingEditorImpl';
4242
import { DiffMapping, DiffModel } from './diffModel';
4343
import { Range } from 'vs/editor/common/core/range';
4444
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer';
45+
import { deepClone } from 'vs/base/common/objects';
4546

4647
const diffEditorDefaultOptions: ValidDiffEditorBaseOptions = {
4748
enableSplitViewResizing: true,
@@ -82,6 +83,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
8283
);
8384
private readonly _rootSizeObserver: ObservableElementSizeObserver;
8485
private readonly _options: ISettableObservable<ValidDiffEditorBaseOptions>;
86+
private _editorOptions: IEditorOptions;
8587
private readonly _sash: IObservable<DiffEditorSash | undefined>;
8688
private readonly _boundarySashes = observableValue<IBoundarySashes | undefined>('boundarySashes', undefined);
8789
private readonly _renderOverviewRuler: IObservable<boolean>;
@@ -105,6 +107,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
105107
);
106108

107109
this._options = observableValue<ValidDiffEditorBaseOptions>('options', validateDiffEditorOptions(options || {}, diffEditorDefaultOptions));
110+
this._editorOptions = deepClone(options);
108111

109112
this._domElement.appendChild(this.elements.root);
110113

@@ -431,6 +434,12 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
431434
// Clone minimap options before changing them
432435
clonedOptions.minimap = { ...(clonedOptions.minimap || {}) };
433436
clonedOptions.minimap.enabled = false;
437+
438+
if (this._options.get().experimental?.collapseUnchangedRegions) {
439+
clonedOptions.stickyScroll = { enabled: false };
440+
} else {
441+
clonedOptions.stickyScroll = this._editorOptions.stickyScroll;
442+
}
434443
return clonedOptions;
435444
}
436445

@@ -510,6 +519,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
510519
override updateOptions(_newOptions: IDiffEditorOptions): void {
511520
const newOptions = validateDiffEditorOptions(_newOptions, this._options.get());
512521
this._options.set(newOptions, undefined);
522+
deepMerge(this._editorOptions, deepClone(_newOptions));
513523

514524
this._modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(_newOptions));
515525
this._originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(_newOptions));

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,19 @@ export function animatedObservable(base: IObservable<number, boolean>, store: Di
170170
function easeOutExpo(t: number, b: number, c: number, d: number): number {
171171
return t === d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
172172
}
173+
174+
export function deepMerge<T extends {}>(source1: T, source2: Partial<T>): T {
175+
const result = {} as T;
176+
for (const key in source1) {
177+
result[key] = source1[key];
178+
}
179+
for (const key in source2) {
180+
const source2Value = source2[key];
181+
if (typeof result[key] === 'object' && source2Value && typeof source2Value === 'object') {
182+
result[key] = deepMerge<any>(result[key], source2Value);
183+
} else {
184+
result[key] = source2Value as any;
185+
}
186+
}
187+
return result;
188+
}

0 commit comments

Comments
 (0)