Skip to content

Commit

Permalink
improve zone revealing when showing above line 1 (#213904)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored May 30, 2024
1 parent 3ea4e9e commit 826a005
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
this._disposables.add(this.widget.onDidChangeHeight(() => {
if (this.position) {
// only relayout when visible
this._relayout(this._computeHeightInLines());
this._relayout(this._computeHeight().linesValue);
}
}));
this._disposables.add(this.widget);
Expand Down Expand Up @@ -122,13 +122,13 @@ export class InlineChatZoneWidget extends ZoneWidget {
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + (indentationWidth ?? 0));
}

private _computeHeightInLines(): number {
private _computeHeight(): { linesValue: number; pixelsValue: number } {
const chatContentHeight = this.widget.contentHeight;
const editorHeight = this.editor.getLayoutInfo().height;

const contentHeight = Math.min(chatContentHeight, Math.max(this.widget.minHeight, editorHeight * 0.42));
const heightInLines = contentHeight / this.editor.getOption(EditorOption.lineHeight);
return heightInLines;
return { linesValue: heightInLines, pixelsValue: contentHeight };
}

protected override _onWidth(_widthInPixel: number): void {
Expand All @@ -145,17 +145,32 @@ export class InlineChatZoneWidget extends ZoneWidget {
const marginWithoutIndentation = info.glyphMarginWidth + info.decorationsWidth + info.lineNumbersWidth;
this.container.style.marginLeft = `${marginWithoutIndentation}px`;

super.show(position, this._computeHeightInLines());
const height = this._computeHeight();
super.show(position, height.linesValue);
this._setWidgetMargins(position);
this.widget.chatWidget.setVisible(true);
this.widget.focus();

scrollState.restore(this.editor);
this.editor.revealRangeNearTopIfOutsideViewport(Range.fromPositions(position.delta(-1)), ScrollType.Immediate);

if (position.lineNumber > 1) {
this.editor.revealRangeNearTopIfOutsideViewport(Range.fromPositions(position.delta(-1)), ScrollType.Immediate);
} else {
// reveal top of zone widget
const lineTop = this.editor.getTopForLineNumber(position.lineNumber);
const zoneTop = lineTop - height.pixelsValue;
const spaceBelowLine = this.editor.getScrollHeight() - this.editor.getBottomForLineNumber(position.lineNumber);
const minTop = this.editor.getScrollTop() - spaceBelowLine;
const newTop = Math.max(zoneTop, minTop);

if (newTop < this.editor.getScrollTop()) {
this.editor.setScrollTop(newTop, ScrollType.Immediate);
}
}
}

override updatePositionAndHeight(position: Position): void {
super.updatePositionAndHeight(position, this._computeHeightInLines());
super.updatePositionAndHeight(position, this._computeHeight().linesValue);
this._setWidgetMargins(position);
}

Expand Down

0 comments on commit 826a005

Please sign in to comment.