From 79234820466f6faf13564e03087342f4172780be Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Mon, 24 Jan 2022 14:21:01 +0100 Subject: [PATCH] Fix the 'Cancel' button in comment-sample (#492) The code behind 'Cancel' was identical to the code for 'Save'. Since the commenting API is modifying the body of the comment, we need to save the previous value in the Comment object. --- comment-sample/src/extension.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/comment-sample/src/extension.ts b/comment-sample/src/extension.ts index 7936614b..b238f708 100644 --- a/comment-sample/src/extension.ts +++ b/comment-sample/src/extension.ts @@ -7,6 +7,7 @@ let commentId = 1; class NoteComment implements vscode.Comment { id: number; label: string | undefined; + savedBody: string | vscode.MarkdownString; // for the Cancel button constructor( public body: string | vscode.MarkdownString, public mode: vscode.CommentMode, @@ -15,6 +16,7 @@ class NoteComment implements vscode.Comment { public contextValue?: string ) { this.id = ++commentId; + this.savedBody = this.body; } } @@ -89,6 +91,7 @@ export function activate(context: vscode.ExtensionContext) { comment.parent.comments = comment.parent.comments.map(cmt => { if ((cmt as NoteComment).id === comment.id) { + cmt.body = (cmt as NoteComment).savedBody; cmt.mode = vscode.CommentMode.Preview; } @@ -103,6 +106,7 @@ export function activate(context: vscode.ExtensionContext) { comment.parent.comments = comment.parent.comments.map(cmt => { if ((cmt as NoteComment).id === comment.id) { + (cmt as NoteComment).savedBody = cmt.body; cmt.mode = vscode.CommentMode.Preview; }