Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/vs/workbench/contrib/aideAgent/browser/aideAgentWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
}

private previousTreeScrollHeight: number = 0;
private _userScrolledAway: boolean = false;

private readonly viewModelDisposables = this._register(new DisposableStore());
private _viewModel: ChatViewModel | undefined;
Expand Down Expand Up @@ -406,6 +407,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
if (this.lastItem) {
const offset = Math.max(this.lastItem.currentRenderedHeight ?? 0, 1e6);
this.tree.reveal(this.lastItem, offset);
this._userScrolledAway = false;
}
}

Expand Down Expand Up @@ -634,6 +636,14 @@ export class ChatWidget extends Disposable implements IChatWidget {
}));
this._register(this.tree.onDidScroll(() => {
this._onDidScroll.fire();

// Check if user has scrolled away from the bottom
const scrollTop = this.tree.scrollTop;
const renderHeight = this.tree.renderHeight;
const scrollHeight = this.tree.scrollHeight;

// Consider the user scrolled away if they're not within 2px of the bottom
this._userScrolledAway = scrollTop + renderHeight < scrollHeight - 2;
}));
}

Expand Down Expand Up @@ -665,12 +675,12 @@ export class ChatWidget extends Disposable implements IChatWidget {

private onDidChangeTreeContentHeight(): void {
if (this.tree.scrollHeight !== this.previousTreeScrollHeight) {
// Due to rounding, the scrollTop + renderHeight will not exactly match the scrollHeight.
// Consider the tree to be scrolled all the way down if it is within 2px of the bottom.
const lastElementWasVisible = this.tree.scrollTop + this.tree.renderHeight >= this.previousTreeScrollHeight - 2;
if (lastElementWasVisible) {
// Check if we're near the bottom of the list (within 2px)
const isNearBottom = this.tree.scrollTop + this.tree.renderHeight >= this.previousTreeScrollHeight - 2;

if (isNearBottom && !this._userScrolledAway) {
dom.scheduleAtNextAnimationFrame(dom.getWindow(this.listContainer), () => {
// Can't set scrollTop during this event listener, the list might overwrite the change
// Scroll to the new bottom
this.scrollToEnd();
}, 0);
}
Expand Down Expand Up @@ -1225,4 +1235,4 @@ export class ChatWidgetService implements IAideAgentWidgetService {
toDisposable(() => this._widgets.splice(this._widgets.indexOf(newWidget), 1))
);
}
}
}