finish draft

This commit is contained in:
Peng Lyu
2019-05-17 18:39:54 -07:00
parent 78e140cbb0
commit cfcdec6f41
2 changed files with 25 additions and 1 deletions

View File

@ -60,6 +60,10 @@
{
"command": "mywiki.startDraft",
"title": "Start draft"
},
{
"command": "mywiki.finishDraft",
"title": "Finish draft"
}
],
"menus": {
@ -104,7 +108,14 @@
{
"command": "mywiki.startDraft",
"precondition": "commentIsEmpty",
"group": "navigation"
"group": "navigation",
"when": "!inDraft"
},
{
"command": "mywiki.finishDraft",
"precondition": "commentIsEmpty",
"group": "navigation",
"when": "inDraft"
}
],
"comment/title": [

View File

@ -21,6 +21,7 @@ export function activate(context: vscode.ExtensionContext) {
// A `CommentController` is able to provide comments for documents.
const commentController = vscode.comment.createCommentController('comment-sample', 'Comment API Sample');
context.subscriptions.push(commentController);
vscode.commands.executeCommand('setContext', 'inDraft', false);
// commenting range provider
commentController.commentingRangeProvider = {
@ -43,12 +44,24 @@ export function activate(context: vscode.ExtensionContext) {
}));
context.subscriptions.push(vscode.commands.registerCommand('mywiki.startDraft', (reply: vscode.CommentReply) => {
vscode.commands.executeCommand('setContext', 'inDraft', true);
let thread = reply.thread;
let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread);
newComment.label = 'pending';
thread.comments = [...thread.comments, newComment];
}));
context.subscriptions.push(vscode.commands.registerCommand('mywiki.finishDraft', (reply: vscode.CommentReply) => {
vscode.commands.executeCommand('setContext', 'inDraft', false);
let thread = reply.thread;
let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread);
thread.comments = [...thread.comments, newComment].map(comment => {
comment.label = undefined;
return comment;
});
}));
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);