diff --git a/src/vs/workbench/contrib/comments/browser/commentReply.ts b/src/vs/workbench/contrib/comments/browser/commentReply.ts index 612ca343447..87be57b8f00 100644 --- a/src/vs/workbench/contrib/comments/browser/commentReply.ts +++ b/src/vs/workbench/contrib/comments/browser/commentReply.ts @@ -152,6 +152,15 @@ export class CommentReply extends Disposable { this.commentEditor.focus(); } + public expandReplyAreaAndFocusCommentEditor() { + this.expandReplyArea(); + this.commentEditor.focus(); + } + + public isCommentEditorFocused(): boolean { + return this.commentEditor.hasWidgetFocus(); + } + public getCommentModel() { return this.commentEditor.getModel()!; } diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 88b8b18c57f..148fa2cdeb9 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -28,6 +28,7 @@ import { commentThreadStateBackgroundColorVar, commentThreadStateColorVar } from import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; +import { registerNavigableContainer } from 'vs/workbench/browser/actions/widgetNavigationCommands'; export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration'; @@ -91,6 +92,21 @@ export class CommentThreadWidget extends const bodyElement = dom.$('.body'); container.appendChild(bodyElement); + const tracker = this._register(dom.trackFocus(bodyElement)); + this._register(registerNavigableContainer({ + focusNotifiers: [tracker], + focusNextWidget: () => { + if (!this._commentReply?.isCommentEditorFocused()) { + this._commentReply?.expandReplyAreaAndFocusCommentEditor(); + } + }, + focusPreviousWidget: () => { + if (this._commentReply?.isCommentEditorFocused() && this._commentThread.comments?.length) { + this._body.focus(); + } + } + })); + this._body = this._scopedInstatiationService.createInstance( CommentThreadBody, this._owner,