Skip to content

Commit da54920

Browse files
Fix rendering when chat is hidden (microsoft#191830)
Fixes microsoft#191704
1 parent a33cf1b commit da54920

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/vs/workbench/contrib/chat/browser/chatQuick.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ export class QuickChatService extends Disposable implements IQuickChatService {
9292

9393
// show needs to come after the quickpick is shown
9494
this._currentChat.render(this._container);
95+
} else {
96+
this._currentChat.show();
9597
}
9698

9799
disposableStore.add(this._input.onDidHide(() => {
98100
disposableStore.dispose();
101+
this._currentChat!.hide();
99102
this._input = undefined;
100103
this._onDidClose.fire();
101104
}));
@@ -163,6 +166,14 @@ class QuickChat extends Disposable {
163166
}
164167
}
165168

169+
hide(): void {
170+
this.widget.setVisible(false);
171+
}
172+
173+
show(): void {
174+
this.widget.setVisible(true);
175+
}
176+
166177
render(parent: HTMLElement): void {
167178
if (this.widget) {
168179
throw new Error('Cannot render quick chat twice');

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
213213
this._onDidClear.fire();
214214
}
215215

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

242-
if (this._dynamicMessageLayoutData) {
242+
if (!skipDynamicLayout && this._dynamicMessageLayoutData) {
243243
this.layoutDynamicChatTreeItemMode();
244244
}
245245

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

541541
const mutableDisposable = this._register(new MutableDisposable());
542542
this._register(this.tree.onDidScroll((e) => {
543+
// TODO@TylerLeonhardt this should probably just be disposed when this is disabled
544+
// and then set up again when it is enabled again
545+
if (!this._dynamicMessageLayoutData?.enabled) {
546+
return;
547+
}
543548
mutableDisposable.value = dom.scheduleAtNextAnimationFrame(() => {
544549
if (!e.scrollTopChanged || e.heightChanged || e.scrollHeightChanged) {
545550
return;
@@ -593,7 +598,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
593598
if (!this.viewModel || !this._dynamicMessageLayoutData?.enabled) {
594599
return;
595600
}
596-
const inputHeight = this.inputPart.layout(this._dynamicMessageLayoutData!.maxHeight, this.container.offsetWidth);
601+
602+
const width = this.bodyDimension?.width ?? this.container.offsetWidth;
603+
const inputHeight = this.inputPart.layout(this._dynamicMessageLayoutData!.maxHeight, width);
597604

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

616-
if (needsRerender) {
623+
if (needsRerender || !listHeight) {
617624
// TODO: figure out a better place to reveal the last element
618625
revealLastElement(this.tree);
619626
}

0 commit comments

Comments
 (0)