From 07dcb7aff441bb4b6a4e20271969887085cec327 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 20 Jun 2024 13:05:30 +0200 Subject: [PATCH] inline chat stable scroll should ensure first line stays visible (#216705) --- .../inlineChat/browser/inlineChatZoneWidget.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts index a57b2b9ba4f..3dea5ecc72f 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.ts @@ -184,12 +184,21 @@ export class InlineChatZoneWidget extends ZoneWidget { const lineTop = this.editor.getTopForLineNumber(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); - const newTop = zoneTop; + + const editorHeight = this.editor.getLayoutInfo().height; + const newLineBottom = this.editor.getBottomForLineNumber(lineNumber); + + let newTop: number; + if (newLineBottom > editorHeight) { + newTop = newLineBottom - editorHeight; + } else { + newTop = zoneTop; + } + const currentTop = this.editor.getScrollTop(); + // console.log('REVEAL ZONE TOP', { zoneTop, newLineBottom, editorHeight, currentTop, newTop }); + if (newTop < currentTop) { this.editor.setScrollTop(newTop, ScrollType.Immediate); }