Skip to content

Commit

Permalink
add and use ChatInputPart#contentHeight (#209345)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Apr 2, 2024
1 parent 1c26e87 commit dd0b11c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
39 changes: 25 additions & 14 deletions src/vs/workbench/contrib/chat/browser/chatInputPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
}
}

get contentHeight(): number {
const data = this.getLayoutData();
return data.followupsHeight + data.inputPartEditorHeight + data.inputPartVerticalPadding + data.inputEditorBorder + data.implicitContextHeight;
}

layout(height: number, width: number) {
this.cachedDimensions = new dom.Dimension(width, height);

Expand All @@ -450,25 +455,15 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge

private previousInputEditorDimension: IDimension | undefined;
private _layout(height: number, width: number, allowRecurse = true): void {
const followupsHeight = this.followupsContainer.offsetHeight;

const inputPartBorder = 0;
const inputPartHorizontalPadding = this.options.renderStyle === 'compact' ? 8 : 40;
const inputPartVerticalPadding = this.options.renderStyle === 'compact' ? 12 : 24;
const inputEditorHeight = Math.min(this._inputEditor.getContentHeight(), height - followupsHeight - inputPartVerticalPadding - inputPartBorder, INPUT_EDITOR_MAX_HEIGHT);
const implicitContextHeight = this.implicitContextContainer.offsetHeight;
const data = this.getLayoutData();

const inputEditorBorder = 2;
this._inputPartHeight = followupsHeight + inputEditorHeight + inputPartVerticalPadding + inputPartBorder + inputEditorBorder + implicitContextHeight;
const inputEditorHeight = Math.min(data.inputPartEditorHeight, height - data.followupsHeight - data.inputPartVerticalPadding);

const editorBorder = 2;
const editorPadding = 12;
const executeToolbarWidth = this.cachedToolbarWidth = this.toolbar.getItemsWidth();
const toolbarPadding = 4;
const sideToolbarWidth = this.inputSideToolbarContainer ? dom.getTotalWidth(this.inputSideToolbarContainer) + 4 /*gap*/ : 0;
this._inputPartHeight = data.followupsHeight + inputEditorHeight + data.inputPartVerticalPadding + data.inputEditorBorder + data.implicitContextHeight;

const initialEditorScrollWidth = this._inputEditor.getScrollWidth();
const newEditorWidth = width - inputPartHorizontalPadding - editorBorder - editorPadding - executeToolbarWidth - sideToolbarWidth - toolbarPadding;
const newEditorWidth = width - data.inputPartHorizontalPadding - data.editorBorder - data.editorPadding - data.executeToolbarWidth - data.sideToolbarWidth - data.toolbarPadding;
const newDimension = { width: newEditorWidth, height: inputEditorHeight };
if (!this.previousInputEditorDimension || (this.previousInputEditorDimension.width !== newDimension.width || this.previousInputEditorDimension.height !== newDimension.height)) {
// This layout call has side-effects that are hard to understand. eg if we are calling this inside a onDidChangeContent handler, this can trigger the next onDidChangeContent handler
Expand All @@ -483,6 +478,22 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
}
}

private getLayoutData() {
return {
inputEditorBorder: 2,
followupsHeight: this.followupsContainer.offsetHeight,
inputPartEditorHeight: Math.min(this._inputEditor.getContentHeight(), INPUT_EDITOR_MAX_HEIGHT),
inputPartHorizontalPadding: this.options.renderStyle === 'compact' ? 8 : 40,
inputPartVerticalPadding: this.options.renderStyle === 'compact' ? 12 : 24,
implicitContextHeight: this.implicitContextContainer.offsetHeight,
editorBorder: 2,
editorPadding: 12,
toolbarPadding: 4,
executeToolbarWidth: this.cachedToolbarWidth = this.toolbar.getItemsWidth(),
sideToolbarWidth: this.inputSideToolbarContainer ? dom.getTotalWidth(this.inputSideToolbarContainer) + 4 /*gap*/ : 0,
};
}

saveState(): void {
const inputHistory = this.history.getHistory();
this.historyService.saveHistory(this.providerId!, inputHistory);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
}

get contentHeight(): number {
return dom.getTotalHeight(this.inputPart.element) + this.tree.contentHeight;
return this.inputPart.contentHeight + this.tree.contentHeight;
}

render(parent: HTMLElement): void {
Expand Down

0 comments on commit dd0b11c

Please sign in to comment.