diff --git a/src/vs/workbench/api/common/extHostComments.ts b/src/vs/workbench/api/common/extHostComments.ts index 225cd2b2753..5411bbc9f77 100644 --- a/src/vs/workbench/api/common/extHostComments.ts +++ b/src/vs/workbench/api/common/extHostComments.ts @@ -86,6 +86,53 @@ export class ExtHostComments implements ExtHostCommentsShape { thread: commentThread, text: arg.text }; + } else if (arg && arg.$mid === 9) { + const commentController = this._commentControllers.get(arg.thread.commentControlHandle); + + if (!commentController) { + return arg; + } + + const commentThread = commentController.getCommentThread(arg.thread.commentThreadHandle); + + if (!commentThread) { + return arg; + } + + let commentUniqueId = arg.commentUniqueId; + + let comment = commentThread.getCommentByUniqueId(commentUniqueId); + + if (!comment) { + return arg; + } + + return comment; + + } else if (arg && arg.$mid === 10) { + const commentController = this._commentControllers.get(arg.thread.commentControlHandle); + + if (!commentController) { + return arg; + } + + const commentThread = commentController.getCommentThread(arg.thread.commentThreadHandle); + + if (!commentThread) { + return arg; + } + + let body = arg.text; + let commentUniqueId = arg.commentUniqueId; + + let comment = commentThread.getCommentByUniqueId(commentUniqueId); + + if (!comment) { + return arg; + } + + comment.body = body; + return comment; } return arg; @@ -572,6 +619,18 @@ export class ExtHostCommentThread implements vscode.CommentThread { return undefined; } + getCommentByUniqueId(uniqueId: number): vscode.Comment | undefined { + for (let key of this._commentsMap) { + let comment = key[0]; + let id = key[1]; + if (uniqueId === id) { + return comment; + } + } + + return; + } + dispose() { this._localDisposables.forEach(disposable => disposable.dispose()); this._proxy.$deleteCommentThread( @@ -787,6 +846,7 @@ function convertToModeComment2(thread: ExtHostCommentThread, commentController: return { commentId: vscodeComment.id || vscodeComment.commentId, + mode: vscodeComment.mode, uniqueIdInThread: commentUniqueId, body: extHostTypeConverter.MarkdownString.from(vscodeComment.body), userName: vscodeComment.author ? vscodeComment.author.name : vscodeComment.userName, diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 2bc22702044..ef0f9951425 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -36,7 +36,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; import { MenuItemAction } from 'vs/platform/actions/common/actions'; -import { MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; +import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; const UPDATE_COMMENT_LABEL = nls.localize('label.updateComment', "Update comment"); @@ -193,9 +193,14 @@ export class CommentNode extends Disposable { orientation: ActionsOrientation.HORIZONTAL }); + this.toolbar.context = { + thread: this.commentThread, + commentUniqueId: this.comment.uniqueIdInThread, + $mid: 9 + }; + this.registerActionBarListeners(this._actionsToolbarContainer); this.toolbar.setActions(actions, [])(); - this.toolbar.context = this.comment; this._toDispose.push(this.toolbar); } } @@ -212,7 +217,7 @@ export class CommentNode extends Disposable { let item = new ReactionActionViewItem(action); return item; } else if (action instanceof MenuItemAction) { - let item = new MenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService); + let item = new ContextAwareMenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService); return item; } else { let item = new ActionViewItem({}, action, options); @@ -431,7 +436,9 @@ export class CommentNode extends Disposable { private removeCommentEditor() { this.isEditing = false; - this._editAction.enabled = true; + if (this._editAction) { + this._editAction.enabled = true; + } this._body.classList.remove('hidden'); this._commentEditorModel.dispose(); @@ -523,6 +530,44 @@ export class CommentNode extends Disposable { }); } + public switchToEditMode() { + if (this.isEditing) { + return; + } + + this.isEditing = true; + this._body.classList.add('hidden'); + this._commentEditContainer = dom.append(this._commentDetailsContainer, dom.$('.edit-container')); + this.createCommentEditor(); + + this._errorEditingContainer = dom.append(this._commentEditContainer, dom.$('.validation-error.hidden')); + const formActions = dom.append(this._commentEditContainer, dom.$('.form-actions')); + + let menus = this.commentService.getCommentMenus(this.owner); + let actions = menus.getCommentActions(this.comment); + + actions.forEach(action => { + let button = new Button(formActions); + this._toDispose.push(attachButtonStyler(button, this.themeService)); + + button.label = action.label; + + this._toDispose.push(button.onDidClick(async () => { + let text = this._commentEditor!.getValue(); + + action.run({ + thread: this.commentThread, + commentUniqueId: this.comment.uniqueIdInThread, + text: text, + $mid: 10 + }); + + // this.hideReplyArea(); + this.removeCommentEditor(); + })); + }); + } + private createEditAction(commentDetailsContainer: HTMLElement): Action { return new Action('comment.edit', nls.localize('label.edit', "Edit"), 'octicon octicon-pencil', true, () => { return this.editCommentAction(commentDetailsContainer); @@ -625,6 +670,14 @@ export class CommentNode extends Disposable { if (this.comment.commentReactions && this.comment.commentReactions.length) { this.createReactionsContainer(this._commentDetailsContainer); } + + if (this.comment.mode !== undefined) { + if (this.comment.mode === modes.CommentMode.Editing) { + this.switchToEditMode(); + } else { + this.removeCommentEditor(); + } + } } focus() {