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

Fix rendering when chat is hidden #191830

Merged
merged 1 commit into from
Aug 30, 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
11 changes: 11 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chatQuick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ export class QuickChatService extends Disposable implements IQuickChatService {

// show needs to come after the quickpick is shown
this._currentChat.render(this._container);
} else {
this._currentChat.show();
}

disposableStore.add(this._input.onDidHide(() => {
disposableStore.dispose();
this._currentChat!.hide();
this._input = undefined;
this._onDidClose.fire();
}));
Expand Down Expand Up @@ -162,6 +165,14 @@ class QuickChat extends Disposable {
}
}

hide(): void {
this.widget.setVisible(false);
}

show(): void {
this.widget.setVisible(true);
}

render(parent: HTMLElement): void {
if (this.widget) {
throw new Error('Cannot render quick chat twice');
Expand Down
19 changes: 13 additions & 6 deletions src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
this._onDidClear.fire();
}

private onDidChangeItems() {
private onDidChangeItems(skipDynamicLayout?: boolean) {
if (this.tree && this.visible) {
const treeItems = (this.viewModel?.getItems() ?? [])
.map(item => {
Expand All @@ -239,7 +239,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
}
});

if (this._dynamicMessageLayoutData) {
if (!skipDynamicLayout && this._dynamicMessageLayoutData) {
this.layoutDynamicChatTreeItemMode();
}

Expand Down Expand Up @@ -270,7 +270,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
// Progressive rendering paused while hidden, so start it up again.
// Do it after a timeout because the container is not visible yet (it should be but offsetHeight returns 0 here)
if (this.visible) {
this.onDidChangeItems();
this.onDidChangeItems(true);
}
}, 0));
}
Expand Down Expand Up @@ -540,6 +540,11 @@ export class ChatWidget extends Disposable implements IChatWidget {

const mutableDisposable = this._register(new MutableDisposable());
this._register(this.tree.onDidScroll((e) => {
// TODO@TylerLeonhardt this should probably just be disposed when this is disabled
// and then set up again when it is enabled again
if (!this._dynamicMessageLayoutData?.enabled) {
return;
}
mutableDisposable.value = dom.scheduleAtNextAnimationFrame(() => {
if (!e.scrollTopChanged || e.heightChanged || e.scrollHeightChanged) {
return;
Expand Down Expand Up @@ -593,7 +598,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
if (!this.viewModel || !this._dynamicMessageLayoutData?.enabled) {
return;
}
const inputHeight = this.inputPart.layout(this._dynamicMessageLayoutData!.maxHeight, this.container.offsetWidth);

const width = this.bodyDimension?.width ?? this.container.offsetWidth;
const inputHeight = this.inputPart.layout(this._dynamicMessageLayoutData!.maxHeight, width);

const totalMessages = this.viewModel.getItems();
// grab the last N messages
Expand All @@ -610,10 +617,10 @@ export class ChatWidget extends Disposable implements IChatWidget {
inputHeight + listHeight + (totalMessages.length > 2 ? 18 : 0),
this._dynamicMessageLayoutData!.maxHeight
),
this.container.offsetWidth
width
);

if (needsRerender) {
if (needsRerender || !listHeight) {
// TODO: figure out a better place to reveal the last element
revealLastElement(this.tree);
}
Expand Down