Skip to content

Commit 2c28a90

Browse files
authored
API feedback for activeCommentThread (#204588)
Part of #204484
1 parent d9a95cc commit 2c28a90

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

src/vs/workbench/api/common/extHostComments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
601601

602602
private _activeThread: vscode.CommentThread2 | undefined;
603603

604-
get activeThread(): vscode.CommentThread2 | undefined {
604+
get activeCommentThread(): vscode.CommentThread2 | undefined {
605605
checkProposedApiEnabled(this._extension, 'activeComment');
606606
return this._activeThread;
607607
}
@@ -628,7 +628,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
628628
get reactionHandler(): ReactionHandler | undefined { return that.reactionHandler; },
629629
set reactionHandler(handler: ReactionHandler | undefined) { that.reactionHandler = handler; },
630630
// get activeComment(): vscode.Comment | undefined { return that.activeComment; },
631-
get activeThread(): vscode.CommentThread2 | undefined { return that.activeThread; },
631+
get activeCommentThread(): vscode.CommentThread2 | undefined { return that.activeCommentThread; },
632632
createCommentThread(uri: vscode.Uri, range: vscode.Range | undefined, comments: vscode.Comment[]): vscode.CommentThread | vscode.CommentThread2 {
633633
return that.createCommentThread(uri, range, comments).value;
634634
},

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
174174
this._register(dom.addDisposableListener(this._domNode, dom.EventType.FOCUS_IN, () => {
175175
this.commentService.setActiveCommentAndThread(this.owner, { thread: this.commentThread, comment: this.comment });
176176
}, true));
177-
this._register(dom.addDisposableListener(this._domNode, dom.EventType.FOCUS_OUT, () => {
178-
this.commentService.setActiveCommentAndThread(this.owner, undefined);
179-
}, true));
180177
}
181178

182179
private createScroll(container: HTMLElement, body: HTMLElement) {

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,12 @@ export class CommentReply<T extends IRange | ICellRange> extends Disposable {
233233

234234
private createTextModelListener(commentEditor: ICodeEditor, commentForm: HTMLElement) {
235235
this._commentThreadDisposables.push(commentEditor.onDidFocusEditorWidget(() => {
236-
// Add a setTimeout so that the blur event doesn't fire before the focus event
237-
// https://github.com/microsoft/vscode/blob/f6d945edbdc1b2e8a176624fdf612bb61468944f/src/vs/base/browser/dom.ts#L1322-L1328
238-
setTimeout(() => {
239-
this._commentThread.input = {
240-
uri: commentEditor.getModel()!.uri,
241-
value: commentEditor.getValue()
242-
};
243-
this.commentService.setActiveEditingCommentThread(this._commentThread);
244-
this.commentService.setActiveCommentAndThread(this.owner, { thread: this._commentThread });
245-
}, 0);
246-
}));
247-
248-
this._commentThreadDisposables.push(commentEditor.onDidBlurEditorWidget(() => {
249-
this.commentService.setActiveCommentAndThread(this.owner, undefined);
236+
this._commentThread.input = {
237+
uri: commentEditor.getModel()!.uri,
238+
value: commentEditor.getValue()
239+
};
240+
this.commentService.setActiveEditingCommentThread(this._commentThread);
241+
this.commentService.setActiveCommentAndThread(this.owner, { thread: this._commentThread });
250242
}));
251243

252244
this._commentThreadDisposables.push(commentEditor.getModel()!.onDidChangeContent(() => {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,22 @@ export class CommentService extends Disposable implements ICommentService {
272272
this._onDidChangeActiveEditingCommentThread.fire(commentThread);
273273
}
274274

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

278279
if (!commentController) {
279280
return;
280281
}
281282

283+
if (commentController !== this._lastActiveCommentController) {
284+
await this._lastActiveCommentController?.setActiveCommentAndThread(undefined);
285+
}
286+
this._lastActiveCommentController = commentController;
282287
return commentController.setActiveCommentAndThread(commentInfo);
283288
}
284289

285290
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
286-
if (commentInfos.length) {
287-
this._workspaceHasCommenting.set(true);
288-
}
289291
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
290292
}
291293

src/vscode-dts/vscode.proposed.activeComment.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ declare module 'vscode' {
1515

1616
/**
1717
* The currently active comment thread or `undefined`. The active comment thread is the one
18-
* that currently has focus or, when none has focus, undefined.
18+
* in the CommentController that most recently had focus or, when a different CommentController's
19+
* thread has most recently had focus, undefined.
1920
*/
20-
readonly activeThread: CommentThread | undefined;
21+
readonly activeCommentThread: CommentThread | undefined;
2122
}
2223
}

0 commit comments

Comments
 (0)