Sort comments in view by resource

Part of microsoft/vscode-pull-request-github#3354
This commit is contained in:
Alex Ross 2022-03-14 13:43:55 +01:00
parent 9422f0a568
commit 780cd3096b
No known key found for this signature in database
GPG key ID: 89DDDBA66CBA7840

View file

@ -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<string, ResourceWithCommentThreads[]>();
}
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;
}