Skip to content

Commit c3bd332

Browse files
committed
checking that there is enough available space before doing the indentation
1 parent d3692b2 commit c3bd332

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,18 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
763763

764764
protected override _doLayout(heightInPixel: number): void {
765765

766-
const info = this.editor.getLayoutInfo();
767766
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
768-
const width = Math.min(maxWidth, info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth));
767+
const width = Math.min(maxWidth, this._availableSpaceWithIndentation());
769768
this._dimension = new Dimension(width, heightInPixel);
770769
this.widget.domNode.style.width = `${width}px`;
771770
this.widget.layout(this._dimension);
772771
}
773772

773+
private _availableSpaceWithIndentation(): number {
774+
const info = this.editor.getLayoutInfo();
775+
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth);
776+
}
777+
774778
private _computeHeightInLines(): number {
775779
const lineHeight = this.editor.getOption(EditorOption.lineHeight);
776780
return this.widget.getHeight() / lineHeight;
@@ -809,7 +813,11 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
809813
}
810814
}
811815
this._indentationWidth = this.editor.getOffsetForColumn(indentationLineNumber ?? endLineNumber, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(endLineNumber));
812-
const spaceLeft = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth;
816+
const marginWithoutIndentation = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth;
817+
const marginWithIndentation = marginWithoutIndentation + this._indentationWidth;
818+
const isEnoughAvailableSpaceWithIndentation = this._availableSpaceWithIndentation() > 400;
819+
this._indentationWidth = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
820+
const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation;
813821
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
814822
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
815823
this.widget.domNode.style.marginRight = `${spaceRight}px`;

0 commit comments

Comments
 (0)