Make CommentThread Ctrl+Arrow navigible (#189913)

This commit is contained in:
hsfzxjy 2023-08-11 00:31:37 +08:00 committed by GitHub
parent e83b87f96c
commit 8a7aecc3b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -152,6 +152,15 @@ export class CommentReply<T extends IRange | ICellRange> 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()!;
}

View file

@ -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<T extends IRange | ICellRange = IRange> extends
const bodyElement = <HTMLDivElement>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,