Skip to content

Commit 8f33e45

Browse files
Only update layout when chat is visible (microsoft#191943)
Fixes microsoft#191942
1 parent 4c6dbcf commit 8f33e45

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class QuickChat extends Disposable {
134134
private model: ChatModel | undefined;
135135
private _currentQuery: string | undefined;
136136
private maintainScrollTimer: MutableDisposable<IDisposable> = this._register(new MutableDisposable<IDisposable>());
137+
private _deferUpdatingDynamicLayout: boolean = false;
137138

138139
constructor(
139140
private readonly _options: IChatViewOptions,
@@ -183,6 +184,10 @@ class QuickChat extends Disposable {
183184
this.widget.setVisible(true);
184185
// If the mutable disposable is set, then we are keeping the existing scroll position
185186
// so we should not update the layout.
187+
if (this._deferUpdatingDynamicLayout) {
188+
this._deferUpdatingDynamicLayout = false;
189+
this.widget.updateDynamicChatTreeItemLayout(2, this.maxHeight);
190+
}
186191
if (!this.maintainScrollTimer.value) {
187192
this.widget.layoutDynamicChatTreeItemMode();
188193
}
@@ -222,7 +227,14 @@ class QuickChat extends Disposable {
222227

223228
private registerListeners(parent: HTMLElement): void {
224229
this._register(this.layoutService.onDidLayout(() => {
225-
this.widget.updateDynamicChatTreeItemLayout(2, this.maxHeight);
230+
if (this.widget.visible) {
231+
this.widget.updateDynamicChatTreeItemLayout(2, this.maxHeight);
232+
} else {
233+
// If the chat is not visible, then we should defer updating the layout
234+
// because it relies on offsetHeight which only works correctly
235+
// when the chat is visible.
236+
this._deferUpdatingDynamicLayout = true;
237+
}
226238
}));
227239
this._register(this.widget.inputEditor.onDidChangeModelContent((e) => {
228240
this._currentQuery = this.widget.inputEditor.getValue();

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ export class ChatWidget extends Disposable implements IChatWidget {
7777
private container!: HTMLElement;
7878

7979
private bodyDimension: dom.Dimension | undefined;
80-
private visible = false;
8180
private visibleChangeCount = 0;
8281
private requestInProgress: IContextKey<boolean>;
82+
private _visible = false;
83+
public get visible() {
84+
return this._visible;
85+
}
8386

8487
private previousTreeScrollHeight: number = 0;
8588

@@ -214,7 +217,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
214217
}
215218

216219
private onDidChangeItems(skipDynamicLayout?: boolean) {
217-
if (this.tree && this.visible) {
220+
if (this.tree && this._visible) {
218221
const treeItems = (this.viewModel?.getItems() ?? [])
219222
.map(item => {
220223
return <ITreeElement<ChatTreeItem>>{
@@ -261,15 +264,15 @@ export class ChatWidget extends Disposable implements IChatWidget {
261264
}
262265

263266
setVisible(visible: boolean): void {
264-
this.visible = visible;
267+
this._visible = visible;
265268
this.visibleChangeCount++;
266269
this.renderer.setVisible(visible);
267270

268271
if (visible) {
269272
this._register(disposableTimeout(() => {
270273
// Progressive rendering paused while hidden, so start it up again.
271274
// Do it after a timeout because the container is not visible yet (it should be but offsetHeight returns 0 here)
272-
if (this.visible) {
275+
if (this._visible) {
273276
this.onDidChangeItems(true);
274277
}
275278
}, 0));

0 commit comments

Comments
 (0)