diff --git a/src/vs/workbench/api/browser/mainThreadComments.ts b/src/vs/workbench/api/browser/mainThreadComments.ts index 9a6f866362c73899067ecc858a5a392c8abd458d..aa0e454810a601aaef0a7c534b4907a9ddda2ea0 100644 --- a/src/vs/workbench/api/browser/mainThreadComments.ts +++ b/src/vs/workbench/api/browser/mainThreadComments.ts @@ -469,6 +469,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments private _handlers = new Map(); private _commentControllers = new Map(); + private _activeCommentThread?: MainThreadCommentThread; + private _input?: modes.CommentInput; + private _openPanelListener: IDisposable | null; constructor( @@ -483,6 +486,26 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._disposables = []; this._activeCommentThreadDisposables = []; this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments); + + this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => { + let handle = (thread as MainThreadCommentThread).controllerHandle; + let controller = this._commentControllers.get(handle); + + if (!controller) { + return; + } + + this._activeCommentThreadDisposables = dispose(this._activeCommentThreadDisposables); + this._activeCommentThread = thread as MainThreadCommentThread; + controller.activeCommentThread = this._activeCommentThread; + + this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose + this._input = input; + this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined); + })); + + await this._proxy.$onCommentWidgetInputChange(controller.handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread.range, this._input ? this._input.value : undefined); + })); } $registerCommentController(handle: number, id: string, label: string): void { diff --git a/src/vs/workbench/browser/web.simpleservices.ts b/src/vs/workbench/browser/web.simpleservices.ts index 3920c5d2d3163ad5505f7bf0a32c9e176fe923bc..49385f06a2ecb57303e136bb6bd6c94dc8998ab1 100644 --- a/src/vs/workbench/browser/web.simpleservices.ts +++ b/src/vs/workbench/browser/web.simpleservices.ts @@ -619,6 +619,7 @@ export class SimpleCommentService implements ICommentService { onDidSetAllCommentThreads: Event = Event.None; onDidUpdateCommentThreads: Event = Event.None; onDidChangeActiveCommentingRange: Event<{ range: Range; commentingRangesInfo: CommentingRanges; }> = Event.None; + onDidChangeActiveCommentThread: Event = Event.None; onDidSetDataProvider: Event = Event.None; onDidDeleteDataProvider: Event = Event.None; setDocumentComments: any; @@ -649,6 +650,7 @@ export class SimpleCommentService implements ICommentService { deleteReaction: any; getReactionGroup: any; toggleReaction: any; + setActiveCommentThread: any; } registerSingleton(ICommentService, SimpleCommentService, true); //#endregion diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 56c2a8667f99aad0a73938c3d7724625c6ff57e0..09e2426a914e1d389bb2509f825efc8b2c51a964 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -424,12 +424,14 @@ export class CommentNode extends Disposable { uri: this._commentEditor.getModel()!.uri, value: this.comment.body.value }; + this.commentService.setActiveCommentThread(commentThread); this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => { commentThread.input = { uri: this._commentEditor!.getModel()!.uri, value: this.comment.body.value }; + this.commentService.setActiveCommentThread(commentThread); })); this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => { @@ -439,6 +441,7 @@ export class CommentNode extends Disposable { let input = commentThread.input; input.value = newVal; commentThread.input = input; + this.commentService.setActiveCommentThread(commentThread); } } })); @@ -486,6 +489,7 @@ export class CommentNode extends Disposable { uri: this._commentEditor.getModel()!.uri, value: newBody }; + this.commentService.setActiveCommentThread(commentThread); let commandId = this.comment.editCommand.id; let args = this.comment.editCommand.arguments || []; @@ -523,6 +527,7 @@ export class CommentNode extends Disposable { if (result.confirmed) { try { if (this.comment.deleteCommand) { + this.commentService.setActiveCommentThread(this.commentThread); let commandId = this.comment.deleteCommand.id; let args = this.comment.deleteCommand.arguments || []; diff --git a/src/vs/workbench/contrib/comments/browser/commentService.ts b/src/vs/workbench/contrib/comments/browser/commentService.ts index 4823e3aec3ad85cce2356aa413e0707227a178bc..9b2286d4677f01a58f4a3f16b3d0661a43005b92 100644 --- a/src/vs/workbench/contrib/comments/browser/commentService.ts +++ b/src/vs/workbench/contrib/comments/browser/commentService.ts @@ -38,6 +38,7 @@ export interface ICommentService { readonly onDidSetResourceCommentInfos: Event; readonly onDidSetAllCommentThreads: Event; readonly onDidUpdateCommentThreads: Event; + readonly onDidChangeActiveCommentThread: Event; readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>; readonly onDidSetDataProvider: Event; readonly onDidDeleteDataProvider: Event; @@ -69,6 +70,7 @@ export interface ICommentService { deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise; getReactionGroup(owner: string): CommentReaction[] | undefined; toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise; + setActiveCommentThread(commentThread: CommentThread | null): void; } export class CommentService extends Disposable implements ICommentService { @@ -89,6 +91,9 @@ export class CommentService extends Disposable implements ICommentService { private readonly _onDidUpdateCommentThreads: Emitter = this._register(new Emitter()); readonly onDidUpdateCommentThreads: Event = this._onDidUpdateCommentThreads.event; + private readonly _onDidChangeActiveCommentThread = this._register(new Emitter()); + readonly onDidChangeActiveCommentThread = this._onDidChangeActiveCommentThread.event; + private readonly _onDidChangeActiveCommentingRange: Emitter<{ range: Range, commentingRangesInfo: CommentingRanges @@ -109,6 +114,10 @@ export class CommentService extends Disposable implements ICommentService { super(); } + setActiveCommentThread(commentThread: CommentThread | null) { + this._onDidChangeActiveCommentThread.fire(commentThread); + } + setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void { this._onDidSetResourceCommentInfos.fire({ resource, commentInfos }); } diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 9d11f9114bffab19dcc10474df57bd44080607ed..737fe7297d40e165940c7aa86a5e122a8397b163 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -211,6 +211,10 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget this._bodyElement = dom.$('.body'); container.appendChild(this._bodyElement); + + dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => { + this.commentService.setActiveCommentThread(this._commentThread); + }); } protected _fillHead(container: HTMLElement): void { @@ -265,6 +269,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget } else { const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand; if (deleteCommand) { + this.commentService.setActiveCommentThread(this._commentThread); return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || [])); } else if (this._commentEditor.getValue() === '') { this.commentService.disposeCommentThread(this._owner, this._commentThread.threadId!); @@ -516,6 +521,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; + this.commentService.setActiveCommentThread(this._commentThread); })); this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => { @@ -526,6 +532,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget newInput.value = modelContent; thread.input = newInput; } + this.commentService.setActiveCommentThread(this._commentThread); })); this._commentThreadDisposables.push((this._commentThread as modes.CommentThread2).onDidChangeInput(input => { @@ -727,6 +734,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; + this.commentService.setActiveCommentThread(this._commentThread); await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || [])); })); @@ -751,6 +759,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; + this.commentService.setActiveCommentThread(this._commentThread); await this.commandService.executeCommand(command.id, ...(command.arguments || [])); })); }); @@ -821,6 +830,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; + this.commentService.setActiveCommentThread(this._commentThread); let commandId = commentThread.acceptInputCommand.id; let args = commentThread.acceptInputCommand.arguments || [];