checking that there is enough available space before doing the indentation

This commit is contained in:
Aiday Marlen Kyzy
2023-06-08 16:33:38 +02:00
parent d3692b2a98
commit c3bd33203d
@@ -763,14 +763,18 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
protected override _doLayout(heightInPixel: number): void {
const info = this.editor.getLayoutInfo();
const maxWidth = !this.widget.showsAnyPreview() ? 640 : Number.MAX_SAFE_INTEGER;
const width = Math.min(maxWidth, info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth));
const width = Math.min(maxWidth, this._availableSpaceWithIndentation());
this._dimension = new Dimension(width, heightInPixel);
this.widget.domNode.style.width = `${width}px`;
this.widget.layout(this._dimension);
}
private _availableSpaceWithIndentation(): number {
const info = this.editor.getLayoutInfo();
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth);
}
private _computeHeightInLines(): number {
const lineHeight = this.editor.getOption(EditorOption.lineHeight);
return this.widget.getHeight() / lineHeight;
@@ -809,7 +813,11 @@ export class InteractiveEditorZoneWidget extends ZoneWidget {
}
}
this._indentationWidth = this.editor.getOffsetForColumn(indentationLineNumber ?? endLineNumber, indentationLevel ?? viewModel.getLineFirstNonWhitespaceColumn(endLineNumber));
const spaceLeft = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth + this._indentationWidth;
const marginWithoutIndentation = info.lineNumbersWidth + info.glyphMarginWidth + info.decorationsWidth;
const marginWithIndentation = marginWithoutIndentation + this._indentationWidth;
const isEnoughAvailableSpaceWithIndentation = this._availableSpaceWithIndentation() > 400;
this._indentationWidth = isEnoughAvailableSpaceWithIndentation ? this._indentationWidth : 0;
const spaceLeft = isEnoughAvailableSpaceWithIndentation ? marginWithIndentation : marginWithoutIndentation;
const spaceRight = info.minimap.minimapWidth + info.verticalScrollbarWidth;
this.widget.domNode.style.marginLeft = `${spaceLeft}px`;
this.widget.domNode.style.marginRight = `${spaceRight}px`;