Skip to content

Commit 10171ed

Browse files
authored
Synchronizes in-editor scrolling back to virtual list scrolling. (microsoft#205959)
Fixes revealing issues.
1 parent 6eec64e commit 10171ed

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/vs/editor/browser/widget/multiDiffEditorWidget/diffEditorItemTemplate.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActio
2424
export class TemplateData implements IObjectData {
2525
constructor(
2626
public readonly viewModel: DocumentDiffItemViewModel,
27+
public readonly deltaScrollVertical: (delta: number) => void,
2728
) { }
2829

2930

@@ -116,15 +117,15 @@ export class DiffEditorItemTemplate extends Disposable implements IPooledObject<
116117
this._elements.editor.style.display = this._collapsed.read(reader) ? 'none' : 'block';
117118
}));
118119

119-
this.editor.getModifiedEditor().onDidLayoutChange(e => {
120+
this._register(this.editor.getModifiedEditor().onDidLayoutChange(e => {
120121
const width = this.editor.getModifiedEditor().getLayoutInfo().contentWidth;
121122
this._modifiedWidth.set(width, undefined);
122-
});
123+
}));
123124

124-
this.editor.getOriginalEditor().onDidLayoutChange(e => {
125+
this._register(this.editor.getOriginalEditor().onDidLayoutChange(e => {
125126
const width = this.editor.getOriginalEditor().getLayoutInfo().contentWidth;
126127
this._originalWidth.set(width, undefined);
127-
});
128+
}));
128129

129130
this._register(this.editor.onDidContentSizeChange(e => {
130131
globalTransaction(tx => {
@@ -134,6 +135,18 @@ export class DiffEditorItemTemplate extends Disposable implements IPooledObject<
134135
});
135136
}));
136137

138+
this._register(this.editor.getOriginalEditor().onDidScrollChange(e => {
139+
if (this._isSettingScrollTop) {
140+
return;
141+
}
142+
143+
if (!e.scrollTopChanged || !this._data) {
144+
return;
145+
}
146+
const delta = e.scrollTop - this._lastScrollTop;
147+
this._data.deltaScrollVertical(delta);
148+
}));
149+
137150
this._register(autorun(reader => {
138151
const isFocused = this.isFocused.read(reader);
139152
this._elements.root.classList.toggle('focused', isFocused);
@@ -162,7 +175,10 @@ export class DiffEditorItemTemplate extends Disposable implements IPooledObject<
162175

163176
private readonly _dataStore = new DisposableStore();
164177

178+
private _data: TemplateData | undefined;
179+
165180
public setData(data: TemplateData): void {
181+
this._data = data;
166182
function updateOptions(options: IDiffEditorOptions): IDiffEditorOptions {
167183
return {
168184
...options,
@@ -222,6 +238,9 @@ export class DiffEditorItemTemplate extends Disposable implements IPooledObject<
222238

223239
private readonly _headerHeight = /*this._elements.header.clientHeight*/ 48;
224240

241+
private _lastScrollTop = -1;
242+
private _isSettingScrollTop = false;
243+
225244
public render(verticalRange: OffsetRange, width: number, editorScroll: number, viewPort: OffsetRange): void {
226245
this._elements.root.style.visibility = 'visible';
227246
this._elements.root.style.top = `${verticalRange.start}px`;
@@ -240,7 +259,13 @@ export class DiffEditorItemTemplate extends Disposable implements IPooledObject<
240259
height: verticalRange.length - this._outerEditorHeight,
241260
});
242261
});
243-
this.editor.getOriginalEditor().setScrollTop(editorScroll);
262+
try {
263+
this._isSettingScrollTop = true;
264+
this._lastScrollTop = editorScroll;
265+
this.editor.getOriginalEditor().setScrollTop(editorScroll);
266+
} finally {
267+
this._isSettingScrollTop = false;
268+
}
244269

245270
this._elements.header.classList.toggle('shadow', delta > 0 || editorScroll > 0);
246271
this._elements.header.classList.toggle('collapsed', delta === maxDelta);

src/vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidgetImpl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
7676
}
7777
const items = vm.items.read(reader);
7878
return items.map(d => {
79-
const item = store.add(new VirtualizedViewItem(d, this._objectPool, this.scrollLeft));
79+
const item = store.add(new VirtualizedViewItem(d, this._objectPool, this.scrollLeft, delta => {
80+
this._scrollableElement.setScrollPosition({ scrollTop: this._scrollableElement.getScrollPosition().scrollTop + delta });
81+
}));
8082
const data = this._lastDocStates?.[item.getKey()];
8183
if (data) {
8284
transaction(tx => {
@@ -344,6 +346,7 @@ class VirtualizedViewItem extends Disposable {
344346
public readonly viewModel: DocumentDiffItemViewModel,
345347
private readonly _objectPool: ObjectPool<TemplateData, DiffEditorItemTemplate>,
346348
private readonly _scrollLeft: IObservable<number>,
349+
private readonly _deltaScrollVertical: (delta: number) => void,
347350
) {
348351
super();
349352

@@ -434,7 +437,7 @@ class VirtualizedViewItem extends Disposable {
434437

435438
let ref = this._templateRef.get();
436439
if (!ref) {
437-
ref = this._objectPool.getUnusedObj(new TemplateData(this.viewModel));
440+
ref = this._objectPool.getUnusedObj(new TemplateData(this.viewModel, this._deltaScrollVertical));
438441
this._templateRef.set(ref, undefined);
439442

440443
const selections = this.viewModel.lastTemplateData.get().selections;

0 commit comments

Comments
 (0)