Skip to content

Commit

Permalink
API feedback for activeCommentThread (#204588)
Browse files Browse the repository at this point in the history
Part of #204484
  • Loading branch information
alexr00 authored Feb 7, 2024
1 parent d9a95cc commit 2c28a90
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo

private _activeThread: vscode.CommentThread2 | undefined;

get activeThread(): vscode.CommentThread2 | undefined {
get activeCommentThread(): vscode.CommentThread2 | undefined {
checkProposedApiEnabled(this._extension, 'activeComment');
return this._activeThread;
}
Expand All @@ -628,7 +628,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
get reactionHandler(): ReactionHandler | undefined { return that.reactionHandler; },
set reactionHandler(handler: ReactionHandler | undefined) { that.reactionHandler = handler; },
// get activeComment(): vscode.Comment | undefined { return that.activeComment; },
get activeThread(): vscode.CommentThread2 | undefined { return that.activeThread; },
get activeCommentThread(): vscode.CommentThread2 | undefined { return that.activeCommentThread; },
createCommentThread(uri: vscode.Uri, range: vscode.Range | undefined, comments: vscode.Comment[]): vscode.CommentThread | vscode.CommentThread2 {
return that.createCommentThread(uri, range, comments).value;
},
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
this._register(dom.addDisposableListener(this._domNode, dom.EventType.FOCUS_IN, () => {
this.commentService.setActiveCommentAndThread(this.owner, { thread: this.commentThread, comment: this.comment });
}, true));
this._register(dom.addDisposableListener(this._domNode, dom.EventType.FOCUS_OUT, () => {
this.commentService.setActiveCommentAndThread(this.owner, undefined);
}, true));
}

private createScroll(container: HTMLElement, body: HTMLElement) {
Expand Down
20 changes: 6 additions & 14 deletions src/vs/workbench/contrib/comments/browser/commentReply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,12 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {

private createTextModelListener(commentEditor: ICodeEditor, commentForm: HTMLElement) {
this._commentThreadDisposables.push(commentEditor.onDidFocusEditorWidget(() => {
// Add a setTimeout so that the blur event doesn't fire before the focus event
// https://github.com/microsoft/vscode/blob/f6d945edbdc1b2e8a176624fdf612bb61468944f/src/vs/base/browser/dom.ts#L1322-L1328
setTimeout(() => {
this._commentThread.input = {
uri: commentEditor.getModel()!.uri,
value: commentEditor.getValue()
};
this.commentService.setActiveEditingCommentThread(this._commentThread);
this.commentService.setActiveCommentAndThread(this.owner, { thread: this._commentThread });
}, 0);
}));

this._commentThreadDisposables.push(commentEditor.onDidBlurEditorWidget(() => {
this.commentService.setActiveCommentAndThread(this.owner, undefined);
this._commentThread.input = {
uri: commentEditor.getModel()!.uri,
value: commentEditor.getValue()
};
this.commentService.setActiveEditingCommentThread(this._commentThread);
this.commentService.setActiveCommentAndThread(this.owner, { thread: this._commentThread });
}));

this._commentThreadDisposables.push(commentEditor.getModel()!.onDidChangeContent(() => {
Expand Down
8 changes: 5 additions & 3 deletions src/vs/workbench/contrib/comments/browser/commentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,22 @@ export class CommentService extends Disposable implements ICommentService {
this._onDidChangeActiveEditingCommentThread.fire(commentThread);
}

private _lastActiveCommentController: ICommentController | undefined;
async setActiveCommentAndThread(owner: string, commentInfo: { thread: CommentThread<IRange>; comment?: Comment } | undefined) {
const commentController = this._commentControls.get(owner);

if (!commentController) {
return;
}

if (commentController !== this._lastActiveCommentController) {
await this._lastActiveCommentController?.setActiveCommentAndThread(undefined);
}
this._lastActiveCommentController = commentController;
return commentController.setActiveCommentAndThread(commentInfo);
}

setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
if (commentInfos.length) {
this._workspaceHasCommenting.set(true);
}
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
}

Expand Down
5 changes: 3 additions & 2 deletions src/vscode-dts/vscode.proposed.activeComment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ declare module 'vscode' {

/**
* The currently active comment thread or `undefined`. The active comment thread is the one
* that currently has focus or, when none has focus, undefined.
* in the CommentController that most recently had focus or, when a different CommentController's
* thread has most recently had focus, undefined.
*/
readonly activeThread: CommentThread | undefined;
readonly activeCommentThread: CommentThread | undefined;
}
}

0 comments on commit 2c28a90

Please sign in to comment.