Skip to content

Commit 572f57d

Browse files
authored
Merge pull request #11 from RefactorSecurity/fix-note-status-change
Fix update for note status when using brackets in notes
2 parents 1014182 + 9613a87 commit 572f57d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/helpers.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const saveNoteComment = (
2929
);
3030
thread.comments = [...thread.comments, newComment];
3131
if (firstComment) {
32-
updateNoteStatus(newComment, NoteStatus.TODO);
32+
updateNoteStatus(newComment, NoteStatus.TODO, true);
3333
thread.contextValue = uuidv4();
3434
noteMap.set(thread.contextValue, thread);
3535
}
@@ -46,7 +46,7 @@ export const setNoteStatus = (
4646
remoteDb?: RemoteDb,
4747
) => {
4848
// Prepend new status on first note comment
49-
updateNoteStatus(thread.comments[0], status);
49+
updateNoteStatus(thread.comments[0], status, false);
5050

5151
// Add note comment about status change
5252
saveNoteComment(
@@ -59,9 +59,21 @@ export const setNoteStatus = (
5959
);
6060
};
6161

62-
const updateNoteStatus = (comment: vscode.Comment, status: NoteStatus) => {
63-
// Remove previous status if any
64-
comment.body = comment.body.toString().replace(/^\[.*\] /, '');
62+
const updateNoteStatus = (
63+
comment: vscode.Comment,
64+
status: NoteStatus,
65+
firstComment: boolean,
66+
) => {
67+
// Remove previous status if not first comment
68+
if (!firstComment) {
69+
let removed = false;
70+
Object.values(NoteStatus).forEach((noteStatus) => {
71+
if (!removed && comment.body.toString().startsWith(`[${noteStatus}] `)) {
72+
comment.body = comment.body.toString().slice(noteStatus.length + 3);
73+
removed = true;
74+
}
75+
});
76+
}
6577

6678
// Set new status
6779
comment.body = `[${status}] ${comment.body}`;

0 commit comments

Comments
 (0)