Skip to content

Commit

Permalink
Consistently expand or collapse all comments on a line (#176967)
Browse files Browse the repository at this point in the history
* Remove redundant `show()` / `hide()` in `expand()` / `collapse()`

PR #176641 cleaned up the redundant, explicit calls to these methods in
`toggleExpand()` as they already happen in the
`onDidChangeCollapsibleState` listener if `_expanded` doesn't match the
new collapsible state. `hide()` was also adjusted there to call
`deleteCommentThread()` as needed.

* Consistently expand or collapse all comments on a line

Fixes #77155.
  • Loading branch information
hermannloose committed Mar 13, 2023
1 parent 782ea94 commit d492168
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
return this._commentThread;
}

public get expanded(): boolean | undefined {
return this._isExpanded;
}

private _commentOptions: languages.CommentOptions | undefined;

constructor(
Expand Down Expand Up @@ -257,22 +261,12 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this.commentService.disposeCommentThread(this.owner, this._commentThread.threadId);
}

public collapse(): Promise<void> {
public collapse() {
this._commentThread.collapsibleState = languages.CommentThreadCollapsibleState.Collapsed;
if (this._commentThread.comments && this._commentThread.comments.length === 0) {
this.deleteCommentThread();
return Promise.resolve();
}

this.hide();
return Promise.resolve();
}

public expand(): Promise<void> {
public expand() {
this._commentThread.collapsibleState = languages.CommentThreadCollapsibleState.Expanded;

this.show(this.arrowPosition(this._commentThread.range), 2);
return Promise.resolve();
}

public getGlyphPosition(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ export class CommentController implements IEditorContribution {
// The widget's position is undefined until the widget has been displayed, so rely on the glyph position instead
const existingCommentsAtLine = this._commentWidgets.filter(widget => widget.getGlyphPosition() === commentRange.endLineNumber);
if (existingCommentsAtLine.length) {
existingCommentsAtLine.forEach(widget => widget.toggleExpand());
const allExpanded = existingCommentsAtLine.every(widget => widget.expanded);
existingCommentsAtLine.forEach(allExpanded ? widget => widget.collapse() : widget => widget.expand());
this.processNextThreadToAdd();
return;
} else {
Expand Down

0 comments on commit d492168

Please sign in to comment.