Skip to content

Commit 73c3533

Browse files
authored
Ensure new editing comment is focused when expanding a thread (microsoft#223926)
1 parent 2c805c8 commit 73c3533

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
118118
this.expandReplyArea();
119119
} else if (hasExistingComments) {
120120
this.createReplyButton(this.commentEditor, this.form);
121-
} else if (focus && (!this._commentThread.comments || this._commentThread.comments.length === 0)) {
121+
} else if (focus && (this._commentThread.comments && this._commentThread.comments.length === 0)) {
122122
this.expandReplyArea();
123123
}
124124
this._error = dom.append(this.form, dom.$('.validation-error.hidden'));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ export class CommentThreadBody<T extends IRange | ICellRange = IRange> extends D
7070
this._commentsElement.focus();
7171
}
7272

73+
ensureFocusIntoNewEditingComment() {
74+
if (this._commentElements.length === 1 && this._commentElements[0].isEditing) {
75+
this._commentElements[0].setFocus(true);
76+
}
77+
}
78+
7379
async display() {
7480
this._commentsElement = dom.append(this.container, dom.$('div.comments-container'));
7581
this._commentsElement.setAttribute('role', 'presentation');

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
353353
}
354354
}
355355

356+
ensureFocusIntoNewEditingComment() {
357+
this._body.ensureFocusIntoNewEditingComment();
358+
}
359+
356360
focusCommentEditor() {
357361
this._commentReply?.expandReplyAreaAndFocusCommentEditor();
358362
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
423423
this._commentThreadDisposables.push(this._commentThread.onDidChangeCollapsibleState(state => {
424424
if (state === languages.CommentThreadCollapsibleState.Expanded && !this._isExpanded) {
425425
this.show(this.arrowPosition(this._commentThread.range), 2);
426+
this._commentThreadWidget.ensureFocusIntoNewEditingComment();
426427
return;
427428
}
428429

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,7 @@ export class CommentController implements IEditorContribution {
869869
const pendingCommentText = (this._pendingNewCommentCache[uniqueOwner] && this._pendingNewCommentCache[uniqueOwner][thread.threadId])
870870
?? continueOnCommentText;
871871
const pendingEdits = this._pendingEditsCache[uniqueOwner] && this._pendingEditsCache[uniqueOwner][thread.threadId];
872-
const isThreadTemplateOrEmpty = (thread.isTemplate || (!thread.comments || (thread.comments.length === 0)));
873-
const shouldReveal = thread.canReply && isThreadTemplateOrEmpty && (!thread.editorId || (thread.editorId === editorId));
872+
const shouldReveal = thread.canReply && thread.isTemplate && (!thread.comments || (thread.comments.length === 0)) && (!thread.editorId || (thread.editorId === editorId));
874873
await this.displayCommentThread(uniqueOwner, thread, shouldReveal, pendingCommentText, pendingEdits);
875874
this._commentInfos.filter(info => info.uniqueOwner === uniqueOwner)[0].threads.push(thread);
876875
this.tryUpdateReservedSpace();

0 commit comments

Comments
 (0)