Skip to content

Commit 826a005

Browse files
authored
improve zone revealing when showing above line 1 (microsoft#213904)
fixes microsoft#213822
1 parent 3ea4e9e commit 826a005

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
7676
this._disposables.add(this.widget.onDidChangeHeight(() => {
7777
if (this.position) {
7878
// only relayout when visible
79-
this._relayout(this._computeHeightInLines());
79+
this._relayout(this._computeHeight().linesValue);
8080
}
8181
}));
8282
this._disposables.add(this.widget);
@@ -122,13 +122,13 @@ export class InlineChatZoneWidget extends ZoneWidget {
122122
return info.contentWidth - (info.glyphMarginWidth + info.decorationsWidth + (indentationWidth ?? 0));
123123
}
124124

125-
private _computeHeightInLines(): number {
125+
private _computeHeight(): { linesValue: number; pixelsValue: number } {
126126
const chatContentHeight = this.widget.contentHeight;
127127
const editorHeight = this.editor.getLayoutInfo().height;
128128

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

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

148-
super.show(position, this._computeHeightInLines());
148+
const height = this._computeHeight();
149+
super.show(position, height.linesValue);
149150
this._setWidgetMargins(position);
150151
this.widget.chatWidget.setVisible(true);
151152
this.widget.focus();
152153

153154
scrollState.restore(this.editor);
154-
this.editor.revealRangeNearTopIfOutsideViewport(Range.fromPositions(position.delta(-1)), ScrollType.Immediate);
155+
156+
if (position.lineNumber > 1) {
157+
this.editor.revealRangeNearTopIfOutsideViewport(Range.fromPositions(position.delta(-1)), ScrollType.Immediate);
158+
} else {
159+
// reveal top of zone widget
160+
const lineTop = this.editor.getTopForLineNumber(position.lineNumber);
161+
const zoneTop = lineTop - height.pixelsValue;
162+
const spaceBelowLine = this.editor.getScrollHeight() - this.editor.getBottomForLineNumber(position.lineNumber);
163+
const minTop = this.editor.getScrollTop() - spaceBelowLine;
164+
const newTop = Math.max(zoneTop, minTop);
165+
166+
if (newTop < this.editor.getScrollTop()) {
167+
this.editor.setScrollTop(newTop, ScrollType.Immediate);
168+
}
169+
}
155170
}
156171

157172
override updatePositionAndHeight(position: Position): void {
158-
super.updatePositionAndHeight(position, this._computeHeightInLines());
173+
super.updatePositionAndHeight(position, this._computeHeight().linesValue);
159174
this._setWidgetMargins(position);
160175
}
161176

0 commit comments

Comments
 (0)