@@ -409,8 +409,8 @@ export class MainThreadComments extends Disposable implements MainThreadComments
409
409
const commentsPanelAlreadyConstructed = ! ! this . _viewDescriptorService . getViewDescriptorById ( COMMENTS_VIEW_ID ) ;
410
410
if ( ! commentsPanelAlreadyConstructed ) {
411
411
this . registerView ( commentsPanelAlreadyConstructed ) ;
412
- this . registerViewOpenedListener ( commentsPanelAlreadyConstructed ) ;
413
412
}
413
+ this . registerViewListeners ( commentsPanelAlreadyConstructed ) ;
414
414
this . _commentService . setWorkspaceComments ( String ( handle ) , [ ] ) ;
415
415
}
416
416
@@ -513,24 +513,22 @@ export class MainThreadComments extends Disposable implements MainThreadComments
513
513
}
514
514
}
515
515
516
- /**
517
- * If the comments view has never been opened, the constructor for it has not yet run so it has
518
- * no listeners for comment threads being set or updated. Listen for the view opening for the
519
- * first time and send it comments then.
520
- */
521
- private registerViewOpenedListener ( commentsPanelAlreadyConstructed : boolean ) {
522
- if ( ! commentsPanelAlreadyConstructed && ! this . _openViewListener ) {
523
- this . _openViewListener = this . _viewsService . onDidChangeViewVisibility ( e => {
524
- if ( e . id === COMMENTS_VIEW_ID && e . visible ) {
525
- [ ...this . _commentControllers . keys ( ) ] . forEach ( handle => {
526
- let threads = this . _commentControllers . get ( handle ) ! . getAllComments ( ) ;
516
+ private setComments ( ) {
517
+ [ ...this . _commentControllers . keys ( ) ] . forEach ( handle => {
518
+ let threads = this . _commentControllers . get ( handle ) ! . getAllComments ( ) ;
527
519
528
- if ( threads . length ) {
529
- const providerId = this . getHandler ( handle ) ;
530
- this . _commentService . setWorkspaceComments ( providerId , threads ) ;
531
- }
532
- } ) ;
520
+ if ( threads . length ) {
521
+ const providerId = this . getHandler ( handle ) ;
522
+ this . _commentService . setWorkspaceComments ( providerId , threads ) ;
523
+ }
524
+ } ) ;
525
+ }
533
526
527
+ private registerViewOpenedListener ( ) {
528
+ if ( ! this . _openViewListener ) {
529
+ this . _openViewListener = this . _viewsService . onDidChangeViewVisibility ( e => {
530
+ if ( e . id === COMMENTS_VIEW_ID && e . visible ) {
531
+ this . setComments ( ) ;
534
532
if ( this . _openViewListener ) {
535
533
this . _openViewListener . dispose ( ) ;
536
534
this . _openViewListener = null ;
@@ -540,6 +538,31 @@ export class MainThreadComments extends Disposable implements MainThreadComments
540
538
}
541
539
}
542
540
541
+ /**
542
+ * If the comments view has never been opened, the constructor for it has not yet run so it has
543
+ * no listeners for comment threads being set or updated. Listen for the view opening for the
544
+ * first time and send it comments then.
545
+ */
546
+ private registerViewListeners ( commentsPanelAlreadyConstructed : boolean ) {
547
+ if ( ! commentsPanelAlreadyConstructed ) {
548
+ this . registerViewOpenedListener ( ) ;
549
+ }
550
+
551
+ this . _register ( this . _viewDescriptorService . onDidChangeContainer ( e => {
552
+ if ( e . views . find ( view => view . id === COMMENTS_VIEW_ID ) ) {
553
+ this . setComments ( ) ;
554
+ this . registerViewOpenedListener ( ) ;
555
+ }
556
+ } ) ) ;
557
+ this . _register ( this . _viewDescriptorService . onDidChangeContainerLocation ( e => {
558
+ const commentsContainer = this . _viewDescriptorService . getViewContainerByViewId ( COMMENTS_VIEW_ID ) ;
559
+ if ( e . viewContainer . id === commentsContainer ?. id ) {
560
+ this . setComments ( ) ;
561
+ this . registerViewOpenedListener ( ) ;
562
+ }
563
+ } ) ) ;
564
+ }
565
+
543
566
private getHandler ( handle : number ) {
544
567
if ( ! this . _handlers . has ( handle ) ) {
545
568
throw new Error ( 'Unknown handler' ) ;
0 commit comments