mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Use all comment related context keys in commenting sample, fixes https://github.com/microsoft/vscode/issues/74553
This commit is contained in:
@ -61,12 +61,12 @@
|
||||
},
|
||||
{
|
||||
"command": "mywiki.startDraft",
|
||||
"title": "Start draft",
|
||||
"title": "Start Draft",
|
||||
"enablement": "!commentIsEmpty"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.finishDraft",
|
||||
"title": "Finish draft"
|
||||
"title": "Finish Draft"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.dispose",
|
||||
@ -96,49 +96,53 @@
|
||||
{
|
||||
"command": "mywiki.deleteNote",
|
||||
"group": "navigation",
|
||||
"when": "!commentThreadIsEmpty"
|
||||
"when": "commentController == comment-sample && !commentThreadIsEmpty"
|
||||
}
|
||||
],
|
||||
"comments/commentThread/context": [
|
||||
{
|
||||
"command": "mywiki.createNote",
|
||||
"group": "inline",
|
||||
"when": "commentThreadIsEmpty"
|
||||
"when": "commentController == comment-sample && commentThreadIsEmpty"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.replyNote",
|
||||
"group": "inline",
|
||||
"when": "!commentThreadIsEmpty"
|
||||
"when": "commentController == comment-sample && !commentThreadIsEmpty"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.startDraft",
|
||||
"group": "inline",
|
||||
"when": "commentThread != draft"
|
||||
"when": "commentController == comment-sample && commentThreadIsEmpty"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.finishDraft",
|
||||
"group": "inline",
|
||||
"when": "commentThread == draft"
|
||||
"when": "commentController == commment-sample && commentThread == draft"
|
||||
}
|
||||
],
|
||||
"comments/comment/title": [
|
||||
{
|
||||
"command": "mywiki.editNote",
|
||||
"group": "group@1"
|
||||
"group": "group@1",
|
||||
"when": "commentController == comment-sample"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.deleteNoteComment",
|
||||
"group": "group@2"
|
||||
"group": "group@2",
|
||||
"when": "commentController == comment-sample && comment == canDelete"
|
||||
}
|
||||
],
|
||||
"comments/comment/context": [
|
||||
{
|
||||
"command": "mywiki.cancelsaveNote",
|
||||
"group": "inline@1"
|
||||
"group": "inline@1",
|
||||
"when": "commentController == comment-sample"
|
||||
},
|
||||
{
|
||||
"command": "mywiki.saveNote",
|
||||
"group": "inline@2"
|
||||
"group": "inline@2",
|
||||
"when": "commentController == comment-sample"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -11,7 +11,8 @@ class NoteComment implements vscode.Comment {
|
||||
public body: string | vscode.MarkdownString,
|
||||
public mode: vscode.CommentMode,
|
||||
public author: vscode.CommentAuthorInformation,
|
||||
public parent?: vscode.CommentThread
|
||||
public parent?: vscode.CommentThread,
|
||||
public contextValue?: string
|
||||
) {
|
||||
this.id = ++commentId;
|
||||
}
|
||||
@ -21,9 +22,8 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
// A `CommentController` is able to provide comments for documents.
|
||||
const commentController = vscode.comments.createCommentController('comment-sample', 'Comment API Sample');
|
||||
context.subscriptions.push(commentController);
|
||||
vscode.commands.executeCommand('setContext', 'inDraft', false);
|
||||
|
||||
// commenting range provider
|
||||
// A `CommentingRangeProvider` controls where gutter decorations that allow adding comments are shown
|
||||
commentController.commentingRangeProvider = {
|
||||
provideCommentingRanges: (document: vscode.TextDocument, token: vscode.CancellationToken) => {
|
||||
let lineCount = document.lineCount;
|
||||
@ -48,8 +48,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('mywiki.finishDraft', (reply: vscode.CommentReply) => {
|
||||
vscode.commands.executeCommand('setContext', 'inDraft', false);
|
||||
|
||||
let thread = reply.thread;
|
||||
|
||||
if (!thread) {
|
||||
@ -129,7 +127,11 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
function replyNote(reply: vscode.CommentReply) {
|
||||
let thread = reply.thread;
|
||||
let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread);
|
||||
let newComment = new NoteComment(reply.text, vscode.CommentMode.Preview, { name: 'vscode' }, thread, thread.comments.length ? 'canDelete' : undefined);
|
||||
if (thread.contextValue === 'draft') {
|
||||
newComment.label = 'pending';
|
||||
}
|
||||
|
||||
thread.comments = [...thread.comments, newComment];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user