@@ -239,9 +239,21 @@ export class InlineChatController implements IEditorContribution {
239
239
private _showWidget ( initialRender : boolean = false , position ?: Position ) {
240
240
assertType ( this . _editor . hasModel ( ) ) ;
241
241
242
- let widgetPosition = position
243
- ?? this . _zone . value . position
244
- ?? this . _editor . getSelection ( ) . getStartPosition ( ) . delta ( - 1 ) ;
242
+ let widgetPosition : Position ;
243
+ if ( position ) {
244
+ // explicit position wins
245
+ widgetPosition = position ;
246
+ } else if ( this . _zone . value . position ) {
247
+ // already showing - special case of line 1
248
+ if ( this . _zone . value . position . lineNumber === 1 ) {
249
+ widgetPosition = this . _zone . value . position . delta ( - 1 ) ;
250
+ } else {
251
+ widgetPosition = this . _zone . value . position ;
252
+ }
253
+ } else {
254
+ // default to ABOVE the selection
255
+ widgetPosition = this . _editor . getSelection ( ) . getStartPosition ( ) . delta ( - 1 ) ;
256
+ }
245
257
246
258
let needsMargin = false ;
247
259
if ( initialRender ) {
@@ -590,20 +602,27 @@ export class InlineChatController implements IEditorContribution {
590
602
if ( ! request . live ) {
591
603
throw new Error ( 'Progress in NOT supported in non-live mode' ) ;
592
604
}
593
- console . log ( JSON . stringify ( data . edits , undefined , 2 ) ) ;
594
605
progressEdits . push ( data . edits ) ;
595
606
progressiveEditsAvgDuration . update ( progressiveEditsClock . elapsed ( ) ) ;
596
607
progressiveEditsClock . reset ( ) ;
597
608
598
609
progressiveEditsQueue . queue ( async ( ) => {
610
+
611
+ const startThen = this . _activeSession ! . wholeRange . value . getStartPosition ( ) ;
612
+
599
613
// making changes goes into a queue because otherwise the async-progress time will
600
614
// influence the time it takes to receive the changes and progressive typing will
601
615
// become infinitely fast
602
616
await this . _makeChanges ( data . edits ! , data . editsShouldBeInstant
603
617
? undefined
604
618
: { duration : progressiveEditsAvgDuration . value , round : round ++ , token : progressiveEditsCts . token }
605
619
) ;
606
- this . _showWidget ( false ) ;
620
+
621
+ // reshow the widget if the start position changed or shows at the wrong position
622
+ const startNow = this . _activeSession ! . wholeRange . value . getStartPosition ( ) ;
623
+ if ( ! startNow . equals ( startThen ) || ! this . _zone . value . position ?. equals ( startNow ) ) {
624
+ this . _showWidget ( false , startNow . delta ( - 1 ) ) ;
625
+ }
607
626
} ) ;
608
627
}
609
628
if ( data . markdownFragment ) {
0 commit comments