Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable sticky scroll in diff editor when collapse unmodified code is enabled #185434

Merged
merged 1 commit into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import { ViewZoneManager } from 'vs/editor/browser/widget/diffEditorWidget2/line
import { MovedBlocksLinesPart } from 'vs/editor/browser/widget/diffEditorWidget2/movedBlocksLines';
import { OverviewRulerPart } from 'vs/editor/browser/widget/diffEditorWidget2/overviewRulerPart';
import { UnchangedRangesFeature } from 'vs/editor/browser/widget/diffEditorWidget2/unchangedRanges';
import { ObservableElementSizeObserver, applyObservableDecorations } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
import { ObservableElementSizeObserver, applyObservableDecorations, deepMerge } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
import { WorkerBasedDocumentDiffProvider } from 'vs/editor/browser/widget/workerBasedDocumentDiffProvider';
import { EditorOptions, IDiffEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
import { EditorOptions, IDiffEditorOptions, IEditorOptions, ValidDiffEditorBaseOptions, clampedFloat, clampedInt, boolean as validateBooleanOption, stringSet as validateStringSetOption } from 'vs/editor/common/config/editorOptions';
import { IDimension } from 'vs/editor/common/core/dimension';
import { LineRange } from 'vs/editor/common/core/lineRange';
import { Position } from 'vs/editor/common/core/position';
Expand All @@ -42,6 +42,7 @@ import { DelegatingEditor } from './delegatingEditorImpl';
import { DiffMapping, DiffModel } from './diffModel';
import { Range } from 'vs/editor/common/core/range';
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer';
import { deepClone } from 'vs/base/common/objects';

const diffEditorDefaultOptions: ValidDiffEditorBaseOptions = {
enableSplitViewResizing: true,
Expand Down Expand Up @@ -82,6 +83,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
);
private readonly _rootSizeObserver: ObservableElementSizeObserver;
private readonly _options: ISettableObservable<ValidDiffEditorBaseOptions>;
private _editorOptions: IEditorOptions;
private readonly _sash: IObservable<DiffEditorSash | undefined>;
private readonly _boundarySashes = observableValue<IBoundarySashes | undefined>('boundarySashes', undefined);
private readonly _renderOverviewRuler: IObservable<boolean>;
Expand All @@ -105,6 +107,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
);

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

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

Expand Down Expand Up @@ -431,6 +434,12 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
// Clone minimap options before changing them
clonedOptions.minimap = { ...(clonedOptions.minimap || {}) };
clonedOptions.minimap.enabled = false;

if (this._options.get().experimental?.collapseUnchangedRegions) {
clonedOptions.stickyScroll = { enabled: false };
} else {
clonedOptions.stickyScroll = this._editorOptions.stickyScroll;
}
return clonedOptions;
}

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

this._modifiedEditor.updateOptions(this._adjustOptionsForRightHandSide(_newOptions));
this._originalEditor.updateOptions(this._adjustOptionsForLeftHandSide(_newOptions));
Expand Down
16 changes: 16 additions & 0 deletions src/vs/editor/browser/widget/diffEditorWidget2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,19 @@ export function animatedObservable(base: IObservable<number, boolean>, store: Di
function easeOutExpo(t: number, b: number, c: number, d: number): number {
return t === d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
}

export function deepMerge<T extends {}>(source1: T, source2: Partial<T>): T {
hediet marked this conversation as resolved.
Show resolved Hide resolved
const result = {} as T;
for (const key in source1) {
hediet marked this conversation as resolved.
Show resolved Hide resolved
result[key] = source1[key];
}
for (const key in source2) {
const source2Value = source2[key];
if (typeof result[key] === 'object' && source2Value && typeof source2Value === 'object') {
result[key] = deepMerge<any>(result[key], source2Value);
} else {
result[key] = source2Value as any;
}
}
return result;
}