Save comment

This commit is contained in:
Peng Lyu
2019-05-17 18:31:33 -07:00
parent d13c018d78
commit be77259d24
2 changed files with 48 additions and 6 deletions

View File

@ -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"
}
]
}
},

View File

@ -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) {