Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API feedback for activeCommentThread #204588

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}