@@ -76,7 +76,7 @@ export class InlineChatZoneWidget extends ZoneWidget {
76
76
this . _disposables . add ( this . widget . onDidChangeHeight ( ( ) => {
77
77
if ( this . position ) {
78
78
// only relayout when visible
79
- this . _relayout ( this . _computeHeightInLines ( ) ) ;
79
+ this . _relayout ( this . _computeHeight ( ) . linesValue ) ;
80
80
}
81
81
} ) ) ;
82
82
this . _disposables . add ( this . widget ) ;
@@ -122,13 +122,13 @@ export class InlineChatZoneWidget extends ZoneWidget {
122
122
return info . contentWidth - ( info . glyphMarginWidth + info . decorationsWidth + ( indentationWidth ?? 0 ) ) ;
123
123
}
124
124
125
- private _computeHeightInLines ( ) : number {
125
+ private _computeHeight ( ) : { linesValue : number ; pixelsValue : number } {
126
126
const chatContentHeight = this . widget . contentHeight ;
127
127
const editorHeight = this . editor . getLayoutInfo ( ) . height ;
128
128
129
129
const contentHeight = Math . min ( chatContentHeight , Math . max ( this . widget . minHeight , editorHeight * 0.42 ) ) ;
130
130
const heightInLines = contentHeight / this . editor . getOption ( EditorOption . lineHeight ) ;
131
- return heightInLines ;
131
+ return { linesValue : heightInLines , pixelsValue : contentHeight } ;
132
132
}
133
133
134
134
protected override _onWidth ( _widthInPixel : number ) : void {
@@ -145,17 +145,32 @@ export class InlineChatZoneWidget extends ZoneWidget {
145
145
const marginWithoutIndentation = info . glyphMarginWidth + info . decorationsWidth + info . lineNumbersWidth ;
146
146
this . container . style . marginLeft = `${ marginWithoutIndentation } px` ;
147
147
148
- super . show ( position , this . _computeHeightInLines ( ) ) ;
148
+ const height = this . _computeHeight ( ) ;
149
+ super . show ( position , height . linesValue ) ;
149
150
this . _setWidgetMargins ( position ) ;
150
151
this . widget . chatWidget . setVisible ( true ) ;
151
152
this . widget . focus ( ) ;
152
153
153
154
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
+ }
155
170
}
156
171
157
172
override updatePositionAndHeight ( position : Position ) : void {
158
- super . updatePositionAndHeight ( position , this . _computeHeightInLines ( ) ) ;
173
+ super . updatePositionAndHeight ( position , this . _computeHeight ( ) . linesValue ) ;
159
174
this . _setWidgetMargins ( position ) ;
160
175
}
161
176
0 commit comments