diff --git a/src/vs/workbench/contrib/comments/common/commentModel.ts b/src/vs/workbench/contrib/comments/common/commentModel.ts index a9c9fbf27ec..4986e959ffe 100644 --- a/src/vs/workbench/contrib/comments/common/commentModel.ts +++ b/src/vs/workbench/contrib/comments/common/commentModel.ts @@ -6,7 +6,7 @@ import { URI } from 'vs/base/common/uri'; import { IRange } from 'vs/editor/common/core/range'; import { Comment, CommentThread, CommentThreadChangedEvent } from 'vs/editor/common/languages'; -import { groupBy, flatten } from 'vs/base/common/arrays'; +import { groupBy } from 'vs/base/common/arrays'; import { localize } from 'vs/nls'; export interface ICommentThreadChangedEvent extends CommentThreadChangedEvent { @@ -71,9 +71,16 @@ export class CommentsModel { this.commentThreadsMap = new Map(); } + private updateResourceCommentThreads() { + this.resourceCommentThreads = [...this.commentThreadsMap.values()].flat(); + this.resourceCommentThreads.sort((a, b) => { + return a.resource.toString() > b.resource.toString() ? 1 : -1; + }); + } + public setCommentThreads(owner: string, commentThreads: CommentThread[]): void { this.commentThreadsMap.set(owner, this.groupByResource(owner, commentThreads)); - this.resourceCommentThreads = flatten([...this.commentThreadsMap.values()]); + this.updateResourceCommentThreads(); } public updateCommentThreads(event: ICommentThreadChangedEvent): boolean { @@ -123,7 +130,7 @@ export class CommentsModel { }); this.commentThreadsMap.set(owner, threadsForOwner); - this.resourceCommentThreads = flatten([...this.commentThreadsMap.values()]); + this.updateResourceCommentThreads(); return removed.length > 0 || changed.length > 0 || added.length > 0; }