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

Diff Editor v2: Iterates on collapsed unchanged code feature. #185499

Merged
merged 2 commits into from Jun 19, 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
23 changes: 12 additions & 11 deletions build/lib/stylelint/vscode-known-variables.json
Expand Up @@ -101,6 +101,7 @@
"--vscode-diffEditor-removedTextBackground",
"--vscode-diffEditor-removedTextBorder",
"--vscode-diffEditor-unchangedRegionBackground",
"--vscode-diffEditor-unchangedRegionForeground",
"--vscode-diffEditorGutter-insertedLineBackground",
"--vscode-diffEditorGutter-removedLineBackground",
"--vscode-diffEditorOverview-insertedForeground",
Expand Down Expand Up @@ -295,6 +296,16 @@
"--vscode-focusBorder",
"--vscode-foreground",
"--vscode-icon-foreground",
"--vscode-inlineChat-background",
"--vscode-inlineChat-border",
"--vscode-inlineChat-regionHighlight",
"--vscode-inlineChat-shadow",
"--vscode-inlineChatDiff-inserted",
"--vscode-inlineChatInput-background",
"--vscode-inlineChatInput-border",
"--vscode-inlineChatInput-focusBorder",
"--vscode-inlineChatInput-placeholderForeground",
"--vscode-inlineChatrDiff-removed",
"--vscode-input-background",
"--vscode-input-border",
"--vscode-input-foreground",
Expand All @@ -312,16 +323,6 @@
"--vscode-inputValidation-warningBackground",
"--vscode-inputValidation-warningBorder",
"--vscode-inputValidation-warningForeground",
"--vscode-inlineChat-background",
"--vscode-inlineChat-border",
"--vscode-inlineChat-regionHighlight",
"--vscode-inlineChat-shadow",
"--vscode-inlineChatDiff-inserted",
"--vscode-inlineChatDiff-removed",
"--vscode-inlineChatInput-background",
"--vscode-inlineChatInput-border",
"--vscode-inlineChatInput-focusBorder",
"--vscode-inlineChatInput-placeholderForeground",
"--vscode-keybindingLabel-background",
"--vscode-keybindingLabel-border",
"--vscode-keybindingLabel-bottomBorder",
Expand Down Expand Up @@ -745,4 +746,4 @@
"--z-index-run-button-container",
"--zoom-factor"
]
}
}
Expand Up @@ -25,7 +25,7 @@ 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, deepMerge } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
import { ObservableElementSizeObserver, applyObservableDecorations, deepMerge, readHotReloadableExport } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
import { WorkerBasedDocumentDiffProvider } from 'vs/editor/browser/widget/workerBasedDocumentDiffProvider';
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';
Expand All @@ -43,6 +43,7 @@ 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';
import { autorunWithStore2 } from 'vs/base/common/observableImpl/autorun';

const diffEditorDefaultOptions: ValidDiffEditorBaseOptions = {
enableSplitViewResizing: true,
Expand Down Expand Up @@ -88,6 +89,8 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
private readonly _boundarySashes = observableValue<IBoundarySashes | undefined>('boundarySashes', undefined);
private readonly _renderOverviewRuler: IObservable<boolean>;

private unchangedRangesFeature!: UnchangedRangesFeature;

constructor(
private readonly _domElement: HTMLElement,
options: Readonly<IDiffEditorConstructionOptions>,
Expand Down Expand Up @@ -146,18 +149,20 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
});
this._register(keepAlive(this._sash, true));

this._register(new UnchangedRangesFeature(
this._originalEditor,
this._modifiedEditor,
this._diffModel
));
this._register(autorunWithStore2('unchangedRangesFeature', (reader, store) => {
this.unchangedRangesFeature = store.add(new (readHotReloadableExport(UnchangedRangesFeature, reader))(
this._originalEditor, this._modifiedEditor, this._diffModel, this._options.map(o => o.renderSideBySide)
));
}));

this._register(this._instantiationService.createInstance(
ViewZoneManager,
this._originalEditor,
this._modifiedEditor,
this._diffModel,
this._options.map((o) => o.renderSideBySide),
this,
() => this.unchangedRangesFeature.isUpdatingViewZones,
));

this._register(this._instantiationService.createInstance(OverviewRulerPart,
Expand Down
32 changes: 24 additions & 8 deletions src/vs/editor/browser/widget/diffEditorWidget2/diffModel.ts
Expand Up @@ -5,7 +5,7 @@

import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable } from 'vs/base/common/lifecycle';
import { IObservable, IReader, ITransaction, derived, observableSignal, observableSignalFromEvent, observableValue, transaction, waitForState } from 'vs/base/common/observable';
import { IObservable, IReader, ISettableObservable, ITransaction, derived, observableSignal, observableSignalFromEvent, observableValue, transaction, waitForState } from 'vs/base/common/observable';
import { autorunWithStore2 } from 'vs/base/common/observableImpl/autorun';
import { isDefined } from 'vs/base/common/types';
import { LineRange } from 'vs/editor/common/core/lineRange';
Expand Down Expand Up @@ -279,10 +279,14 @@ export class UnchangedRegion {
}

private readonly _visibleLineCountTop = observableValue<number>('visibleLineCountTop', 0);
public readonly visibleLineCountTop: IObservable<number> = this._visibleLineCountTop;
public readonly visibleLineCountTop: ISettableObservable<number> = this._visibleLineCountTop;

private readonly _visibleLineCountBottom = observableValue<number>('visibleLineCountBottom', 0);
public readonly visibleLineCountBottom: IObservable<number> = this._visibleLineCountBottom;
public readonly visibleLineCountBottom: ISettableObservable<number> = this._visibleLineCountBottom;

private readonly _shouldHideControls = derived('isVisible', reader => this.visibleLineCountTop.read(reader) + this.visibleLineCountBottom.read(reader) === this.lineCount && !this.isDragged.read(reader));

public readonly isDragged = observableValue<boolean>('isDragged', false);

constructor(
public readonly originalLineNumber: number,
Expand All @@ -295,6 +299,10 @@ export class UnchangedRegion {
this._visibleLineCountBottom.set(visibleLineCountBottom, undefined);
}

public shouldHideControls(reader: IReader | undefined): boolean {
return this._shouldHideControls.read(reader);
}

public getHiddenOriginalRange(reader: IReader | undefined): LineRange {
return LineRange.ofLength(
this.originalLineNumber + this._visibleLineCountTop.read(reader),
Expand All @@ -309,14 +317,22 @@ export class UnchangedRegion {
);
}

public showMoreAbove(tx: ITransaction | undefined): void {
const maxVisibleLineCountTop = this.lineCount - this._visibleLineCountBottom.get();
this._visibleLineCountTop.set(Math.min(this._visibleLineCountTop.get() + 10, maxVisibleLineCountTop), tx);
public getMaxVisibleLineCountTop() {
return this.lineCount - this._visibleLineCountBottom.get();
}

public getMaxVisibleLineCountBottom() {
return this.lineCount - this._visibleLineCountTop.get();
}

public showMoreAbove(count = 10, tx: ITransaction | undefined): void {
const maxVisibleLineCountTop = this.getMaxVisibleLineCountTop();
this._visibleLineCountTop.set(Math.min(this._visibleLineCountTop.get() + count, maxVisibleLineCountTop), tx);
}

public showMoreBelow(tx: ITransaction | undefined): void {
public showMoreBelow(count = 10, tx: ITransaction | undefined): void {
const maxVisibleLineCountBottom = this.lineCount - this._visibleLineCountTop.get();
this._visibleLineCountBottom.set(Math.min(this._visibleLineCountBottom.get() + 10, maxVisibleLineCountBottom), tx);
this._visibleLineCountBottom.set(Math.min(this._visibleLineCountBottom.get() + count, maxVisibleLineCountBottom), tx);
}

public showAll(tx: ITransaction | undefined): void {
Expand Down
13 changes: 11 additions & 2 deletions src/vs/editor/browser/widget/diffEditorWidget2/lineAlignment.ts
Expand Up @@ -53,6 +53,7 @@ export class ViewZoneManager extends Disposable {
private readonly _diffModel: IObservable<DiffModel | undefined>,
private readonly _renderSideBySide: IObservable<boolean>,
private readonly _diffEditorWidget: DiffEditorWidget2,
private readonly _canIgnoreViewZoneUpdateEvent: () => boolean,
@IClipboardService private readonly _clipboardService: IClipboardService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
) {
Expand All @@ -62,11 +63,11 @@ export class ViewZoneManager extends Disposable {

const originalViewZonesChanged = observableSignalFromEvent(
'origViewZonesChanged',
e => this._originalEditor.onDidChangeViewZones((args) => { if (!isChangingViewZones) { e(args); } })
e => this._originalEditor.onDidChangeViewZones((args) => { if (!isChangingViewZones && !this._canIgnoreViewZoneUpdateEvent()) { e(args); } })
);
const modifiedViewZonesChanged = observableSignalFromEvent(
'modViewZonesChanged',
e => this._modifiedEditor.onDidChangeViewZones((args) => { if (!isChangingViewZones) { e(args); } })
e => this._modifiedEditor.onDidChangeViewZones((args) => { if (!isChangingViewZones && !this._canIgnoreViewZoneUpdateEvent()) { e(args); } })
);

const originalModelTokenizationCompleted = this._diffModel.map(m =>
Expand Down Expand Up @@ -116,6 +117,7 @@ export class ViewZoneManager extends Disposable {
afterLineNumber: 0,
domNode: document.createElement('div'),
heightInPx: modifiedTopPaddingVal,
showInHiddenAreas: true,
});
}
const originalTopPaddingVal = this._originalTopPadding.read(reader);
Expand All @@ -124,6 +126,7 @@ export class ViewZoneManager extends Disposable {
afterLineNumber: 0,
domNode: document.createElement('div'),
heightInPx: originalTopPaddingVal,
showInHiddenAreas: true,
});
}

Expand Down Expand Up @@ -232,6 +235,7 @@ export class ViewZoneManager extends Disposable {
domNode: createFakeLinesDiv(),
heightInPx: a.modifiedHeightInPx,
marginDomNode,
showInHiddenAreas: true,
});
} else {
const delta = a.modifiedHeightInPx - a.originalHeightInPx;
Expand All @@ -244,6 +248,7 @@ export class ViewZoneManager extends Disposable {
afterLineNumber: a.originalRange.endLineNumberExclusive - 1,
domNode: createFakeLinesDiv(),
heightInPx: delta,
showInHiddenAreas: true,
});
} else {
if (syncedMovedText?.lineRangeMapping.modifiedRange.contains(a.modifiedRange.endLineNumberExclusive - 1)) {
Expand All @@ -266,6 +271,7 @@ export class ViewZoneManager extends Disposable {
domNode: createFakeLinesDiv(),
heightInPx: -delta,
marginDomNode,
showInHiddenAreas: true,
});
}
}
Expand Down Expand Up @@ -329,6 +335,9 @@ export class ViewZoneManager extends Disposable {
scrollState.restore(this._modifiedEditor);
}));

this._register(this._originalEditor.onDidScrollChange(e => { this._modifiedEditor.setScrollLeft(e.scrollLeft); }));
this._register(this._modifiedEditor.onDidScrollChange(e => { this._originalEditor.setScrollLeft(e.scrollLeft); }));

this._originalScrollTop = observableFromEvent(this._originalEditor.onDidScrollChange, () => this._originalEditor.getScrollTop());
this._modifiedScrollTop = observableFromEvent(this._modifiedEditor.onDidScrollChange, () => this._modifiedEditor.getScrollTop());

Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions src/vs/editor/browser/widget/diffEditorWidget2/patternTop.svg

This file was deleted.

70 changes: 32 additions & 38 deletions src/vs/editor/browser/widget/diffEditorWidget2/style.css
Expand Up @@ -3,63 +3,57 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

.diff-hidden-lines.showTop {
margin: -5px 0;
.diff-hidden-lines-widget {
width: 100%;
}

.diff-hidden-lines.showTop .top {
height: 7px;
background-color: var(--vscode-diffEditor-unchangedRegionBackground);
mask: url("./patternTop.svg") repeat 0px 0px;
-webkit-mask: url("./patternTop.svg") repeat 0px 0px;
.diff-hidden-lines {
transform: translate(0px, -8px);
font-size: 13px;
line-height: 14px;
}

.diff-hidden-lines.showBottom .bottom {
height: 7px;
background-color: var(--vscode-diffEditor-unchangedRegionBackground);
mask: url("./patternBottom.svg") repeat 10px 0px;
-webkit-mask: url("./patternBottom.svg") repeat 10px 0px;
.diff-hidden-lines:not(.dragging) .top:hover, .diff-hidden-lines:not(.dragging) .bottom:hover, .diff-hidden-lines .top.dragging, .diff-hidden-lines .bottom.dragging {
background-color: var(--vscode-focusBorder);
}

.diff-hidden-lines .center {
background: var(--vscode-diffEditor-unchangedRegionBackground);
padding: 0px 3px;
overflow: hidden;
display: block;
text-overflow: ellipsis;
white-space: nowrap;

height: 20px;
.diff-hidden-lines .top, .diff-hidden-lines .bottom {
transition: background-color 0.1s ease-out;
height: 4px;
background-color: transparent;
background-clip: padding-box;
border-bottom: 2px solid transparent;
border-top: 4px solid transparent;
cursor: pointer;
}

.diff-hidden-lines .center > span,
.diff-hidden-lines .center > a {
user-select: none;
-webkit-user-select: none;
white-space: nowrap;
.diff-hidden-lines .top {
transform: translate(0px, 4px);
}

.diff-hidden-lines .center > a {
text-decoration: none;
.diff-hidden-lines .bottom {
transform: translate(0px, -6px);
}

.diff-hidden-lines .center > a:hover {
cursor: pointer;
color: var(--vscode-editorLink-activeForeground) !important;
}

.diff-hidden-lines .center > a:hover .codicon {
color: var(--vscode-editorLink-activeForeground) !important;
.diff-hidden-lines .center {
background: var(--vscode-diffEditor-unchangedRegionBackground);
color: var(--vscode-diffEditor-unchangedRegionForeground);
overflow: hidden;
display: block;
text-overflow: ellipsis;
white-space: nowrap;

height: 24px;
}

.diff-hidden-lines .center .codicon {
.diff-hidden-lines .center span.codicon {
vertical-align: middle;
color: currentColor !important;
color: var(--vscode-editorCodeLens-foreground);
}

.merge-editor-conflict-actions > a:hover .codicon::before {
.diff-hidden-lines .center a:hover .codicon {
cursor: pointer;
color: var(--vscode-editorLink-activeForeground) !important;
}

.movedOriginal {
Expand Down