mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Save comment
This commit is contained in:
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user