Fix issue with CommentThread focus stealing (#196088)

Writing `vscode.CommentThread.comments` steals focus from Reply input / resets empty Reply input
Fixes #182060
This commit is contained in:
Alex Ross
2023-10-20 16:33:28 +02:00
committed by GitHub
parent c4f155eca1
commit 8b2aec0bda
3 changed files with 7 additions and 9 deletions
@@ -156,7 +156,7 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D
return;
}
updateCommentThread(commentThread: languages.CommentThread<T>) {
updateCommentThread(commentThread: languages.CommentThread<T>, preserveFocus: boolean) {
const oldCommentsLen = this._commentElements.length;
const newCommentsLen = commentThread.comments ? commentThread.comments.length : 0;
@@ -222,7 +222,9 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D
}
this._updateAriaLabel();
this._setFocusedComment(this._focusedComment);
if (!preserveFocus) {
this._setFocusedComment(this._focusedComment);
}
}
private _updateAriaLabel() {
@@ -213,7 +213,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
this._commentThreadDisposables = [];
this._bindCommentThreadListeners();
this._body.updateCommentThread(commentThread);
this._body.updateCommentThread(commentThread, this._commentReply?.isCommentEditorFocused() ?? false);
this._threadIsEmpty.set(!this._body.length);
this._header.updateCommentThread(commentThread);
this._commentReply?.updateCommentThread(commentThread);
@@ -327,13 +327,9 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
}
}
if (shouldMoveWidget && this._isExpanded) {
if ((shouldMoveWidget && this._isExpanded) || (this._commentThread.collapsibleState === languages.CommentThreadCollapsibleState.Expanded && !this._isExpanded)) {
this.show(this.arrowPosition(this._commentThread.range), 2);
}
if (this._commentThread.collapsibleState === languages.CommentThreadCollapsibleState.Expanded) {
this.show(this.arrowPosition(this._commentThread.range), 2);
} else {
} else if (this._commentThread.collapsibleState !== languages.CommentThreadCollapsibleState.Expanded) {
this.hide();
}
}