@@ -325,30 +325,18 @@ export class ReviewCommentController extends CommentControllerBase implements Co
325325 } ) ;
326326
327327 e . changed . forEach ( thread => {
328- const threadMap = thread . isOutdated
329- ? this . _obsoleteFileChangeCommentThreads
330- : thread . diffSide === DiffSide . RIGHT
331- ? this . _workspaceFileChangeCommentThreads
332- : this . _reviewSchemeFileChangeCommentThreads ;
333-
334- const index = threadMap [ thread . path ] ? threadMap [ thread . path ] . findIndex ( t => t . gitHubThreadId === thread . id ) : - 1 ;
335- if ( index > - 1 ) {
336- const matchingThread = threadMap [ thread . path ] [ index ] ;
328+ const match = this . _findMatchingThread ( thread ) ;
329+ if ( match . index > - 1 ) {
330+ const matchingThread = match . threadMap [ thread . path ] [ match . index ] ;
337331 updateThread ( this . _context , matchingThread , thread , githubRepositories ) ;
338332 }
339333 } ) ;
340334
341335 e . removed . forEach ( thread => {
342- const threadMap = thread . isOutdated
343- ? this . _obsoleteFileChangeCommentThreads
344- : thread . diffSide === DiffSide . RIGHT
345- ? this . _workspaceFileChangeCommentThreads
346- : this . _reviewSchemeFileChangeCommentThreads ;
347-
348- const index = threadMap [ thread . path ] ? threadMap [ thread . path ] . findIndex ( t => t . gitHubThreadId === thread . id ) : - 1 ;
349- if ( index > - 1 ) {
350- const matchingThread = threadMap [ thread . path ] [ index ] ;
351- threadMap [ thread . path ] . splice ( index , 1 ) ;
336+ const match = this . _findMatchingThread ( thread ) ;
337+ if ( match . index > - 1 ) {
338+ const matchingThread = match . threadMap [ thread . path ] [ match . index ] ;
339+ match . threadMap [ thread . path ] . splice ( match . index , 1 ) ;
352340 matchingThread . dispose ( ) ;
353341 }
354342 } ) ;
@@ -359,6 +347,28 @@ export class ReviewCommentController extends CommentControllerBase implements Co
359347 this . _register ( vscode . window . onDidChangeActiveTextEditor ( e => this . onDidChangeActiveTextEditor ( e ) ) ) ;
360348 }
361349
350+ private _findMatchingThread ( thread : IReviewThread ) : { threadMap : { [ key : string ] : GHPRCommentThread [ ] } , index : number } {
351+ const threadMap = thread . isOutdated
352+ ? this . _obsoleteFileChangeCommentThreads
353+ : thread . diffSide === DiffSide . RIGHT
354+ ? this . _workspaceFileChangeCommentThreads
355+ : this . _reviewSchemeFileChangeCommentThreads ;
356+
357+ let index = threadMap [ thread . path ] ?. findIndex ( t => t . gitHubThreadId === thread . id ) ?? - 1 ;
358+ if ( ( index === - 1 ) && thread . isOutdated ) {
359+ // The thread has become outdated and needs to be moved to the obsolete threads.
360+ index = this . _workspaceFileChangeCommentThreads [ thread . path ] ?. findIndex ( t => t . gitHubThreadId === thread . id ) ?? - 1 ;
361+ if ( index > - 1 ) {
362+ const matchingThread = this . _workspaceFileChangeCommentThreads [ thread . path ] ! . splice ( index , 1 ) [ 0 ] ;
363+ if ( ! this . _obsoleteFileChangeCommentThreads [ thread . path ] ) {
364+ this . _obsoleteFileChangeCommentThreads [ thread . path ] = [ ] ;
365+ }
366+ this . _obsoleteFileChangeCommentThreads [ thread . path ] ! . push ( matchingThread ) ;
367+ }
368+ }
369+ return { threadMap, index } ;
370+ }
371+
362372 private _commentContentChangedListener : vscode . Disposable | undefined ;
363373 private onDidChangeActiveTextEditor ( editor : vscode . TextEditor | undefined ) {
364374 this . _commentContentChangedListener ?. dispose ( ) ;
0 commit comments