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.
This commit is contained in:
Laurent Le Brun
2022-01-24 14:21:01 +01:00
committed by GitHub
parent c5a751752e
commit 7923482046

View File

@ -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;
}