diff --git a/comment-sample/package.json b/comment-sample/package.json index 6d3b1796..752c358d 100644 --- a/comment-sample/package.json +++ b/comment-sample/package.json @@ -48,6 +48,14 @@ "dark": "resources/close_inverse.svg", "light": "resources/close.svg" } + }, + { + "command": "mywiki.saveNote", + "title": "Save" + }, + { + "command": "mywiki.cancelsaveNote", + "title": "Cancel" } ], "menus": { @@ -99,6 +107,16 @@ "command": "mywiki.deleteNoteComment", "group": "group@2" } + ], + "comment/actions": [ + { + "command": "mywiki.cancelsaveNote", + "group": "group@1" + }, + { + "command": "mywiki.saveNote", + "group": "group@2" + } ] } }, diff --git a/comment-sample/src/extension.ts b/comment-sample/src/extension.ts index d7fe2855..65c54775 100644 --- a/comment-sample/src/extension.ts +++ b/comment-sample/src/extension.ts @@ -29,17 +29,21 @@ export function activate(context: vscode.ExtensionContext) { } }; - let replyNote = (reply: vscode.CommentReply) => { + context.subscriptions.push(vscode.commands.registerCommand('mywiki.createNote', (reply: vscode.CommentReply) => { let thread = reply.thread; let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); thread.comments = [...thread.comments, newComment]; - } - - context.subscriptions.push(vscode.commands.registerCommand('mywiki.createNote', replyNote)); - context.subscriptions.push(vscode.commands.registerCommand('mywiki.replyNote', replyNote)); + })); + + context.subscriptions.push(vscode.commands.registerCommand('mywiki.replyNote', (reply: vscode.CommentReply) => { + let thread = reply.thread; + let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread); + thread.comments = [...thread.comments, newComment]; + })); + context.subscriptions.push(vscode.commands.registerCommand('mywiki.deleteNoteComment', (comment: NoteComment) => { let thread = comment.parent; - thread.comments = thread.comments.filter((cmt: NoteComment) => cmt.id == comment.id); + thread.comments = thread.comments.filter((cmt: NoteComment) => cmt.id !== comment.id); if (thread.comments.length === 0) { thread.dispose(); @@ -50,6 +54,26 @@ export function activate(context: vscode.ExtensionContext) { thread.dispose(); })); + context.subscriptions.push(vscode.commands.registerCommand('mywiki.cancelsaveNote', (comment: NoteComment) => { + comment.parent.comments = comment.parent.comments.map((cmt: NoteComment) => { + if (cmt.id === comment.id) { + cmt.mode = vscode.CommentMode.Preview; + } + + return cmt; + }); + })); + + context.subscriptions.push(vscode.commands.registerCommand('mywiki.saveNote', (comment: NoteComment) => { + comment.parent.comments = comment.parent.comments.map((cmt: NoteComment) => { + if (cmt.id === comment.id) { + cmt.mode = vscode.CommentMode.Preview; + } + + return cmt; + }); + })); + context.subscriptions.push(vscode.commands.registerCommand('mywiki.editNote', (comment: NoteComment) => { comment.parent.comments = comment.parent.comments.map((cmt: NoteComment) => { if (cmt.id === comment.id) {