Skip to content

Commit 192bad6

Browse files
authored
CommentController.activeCommentThread not updated when navigating from ruler or Comments panel (microsoft#223623)
Fixes microsoft#223021
1 parent 1518b11 commit 192bad6

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

src/vs/workbench/contrib/comments/browser/commentThreadZoneWidget.ts

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,39 +187,58 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
187187
}
188188

189189
public reveal(commentUniqueId?: number, focus: CommentWidgetFocus = CommentWidgetFocus.None) {
190+
this.makeVisible(commentUniqueId, focus);
191+
const comment = this._commentThread.comments?.find(comment => comment.uniqueIdInThread === commentUniqueId);
192+
this.commentService.setActiveCommentAndThread(this.uniqueOwner, { thread: this._commentThread, comment });
193+
}
194+
195+
private _expandAndShowZoneWidget() {
190196
if (!this._isExpanded) {
191197
this.show(this.arrowPosition(this._commentThread.range), 2);
192198
}
199+
}
193200

194-
if (commentUniqueId !== undefined) {
195-
const height = this.editor.getLayoutInfo().height;
196-
const coords = this._commentThreadWidget.getCommentCoords(commentUniqueId);
197-
if (coords) {
198-
let scrollTop: number = 1;
199-
if (this._commentThread.range) {
200-
const commentThreadCoords = coords.thread;
201-
const commentCoords = coords.comment;
202-
scrollTop = this.editor.getTopForLineNumber(this._commentThread.range.startLineNumber) - height / 2 + commentCoords.top - commentThreadCoords.top;
203-
}
204-
this.editor.setScrollTop(scrollTop);
205-
if (focus === CommentWidgetFocus.Widget) {
206-
this._commentThreadWidget.focus();
207-
} else if (focus === CommentWidgetFocus.Editor) {
208-
this._commentThreadWidget.focusCommentEditor();
209-
}
210-
return;
201+
private _setFocus(focus: CommentWidgetFocus) {
202+
if (focus === CommentWidgetFocus.Widget) {
203+
this._commentThreadWidget.focus();
204+
} else if (focus === CommentWidgetFocus.Editor) {
205+
this._commentThreadWidget.focusCommentEditor();
206+
}
207+
}
208+
209+
private _goToComment(commentUniqueId: number, focus: CommentWidgetFocus) {
210+
const height = this.editor.getLayoutInfo().height;
211+
const coords = this._commentThreadWidget.getCommentCoords(commentUniqueId);
212+
if (coords) {
213+
let scrollTop: number = 1;
214+
if (this._commentThread.range) {
215+
const commentThreadCoords = coords.thread;
216+
const commentCoords = coords.comment;
217+
scrollTop = this.editor.getTopForLineNumber(this._commentThread.range.startLineNumber) - height / 2 + commentCoords.top - commentThreadCoords.top;
211218
}
219+
this.editor.setScrollTop(scrollTop);
220+
this._setFocus(focus);
221+
} else {
222+
this._goToThread(focus);
212223
}
224+
}
225+
226+
private _goToThread(focus: CommentWidgetFocus) {
213227
const rangeToReveal = this._commentThread.range
214228
? new Range(this._commentThread.range.startLineNumber, this._commentThread.range.startColumn, this._commentThread.range.endLineNumber + 1, 1)
215229
: new Range(1, 1, 1, 1);
216230

217231
this.editor.revealRangeInCenter(rangeToReveal);
218-
if (focus === CommentWidgetFocus.Widget) {
219-
this._commentThreadWidget.focus();
220-
} else if (focus === CommentWidgetFocus.Editor) {
221-
this._commentThreadWidget.focusCommentEditor();
232+
this._setFocus(focus);
233+
}
234+
235+
public makeVisible(commentUniqueId?: number, focus: CommentWidgetFocus = CommentWidgetFocus.None) {
236+
this._expandAndShowZoneWidget();
237+
238+
if (commentUniqueId !== undefined) {
239+
this._goToComment(commentUniqueId, focus);
222240
}
241+
this._goToThread(focus);
223242
}
224243

225244
public getPendingComments(): { newComment: string | undefined; edits: { [key: number]: string } } {
@@ -371,7 +390,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
371390

372391
// If this is a new comment thread awaiting user input then we need to reveal it.
373392
if (shouldReveal) {
374-
this.reveal();
393+
this.makeVisible();
375394
}
376395

377396
this.bindCommentThreadListeners();

0 commit comments

Comments
 (0)