Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const saveNoteComment = (
);
thread.comments = [...thread.comments, newComment];
if (firstComment) {
updateNoteStatus(newComment, NoteStatus.TODO);
updateNoteStatus(newComment, NoteStatus.TODO, true);
thread.contextValue = uuidv4();
noteMap.set(thread.contextValue, thread);
}
Expand All @@ -46,7 +46,7 @@ export const setNoteStatus = (
remoteDb?: RemoteDb,
) => {
// Prepend new status on first note comment
updateNoteStatus(thread.comments[0], status);
updateNoteStatus(thread.comments[0], status, false);

// Add note comment about status change
saveNoteComment(
Expand All @@ -59,9 +59,21 @@ export const setNoteStatus = (
);
};

const updateNoteStatus = (comment: vscode.Comment, status: NoteStatus) => {
// Remove previous status if any
comment.body = comment.body.toString().replace(/^\[.*\] /, '');
const updateNoteStatus = (
comment: vscode.Comment,
status: NoteStatus,
firstComment: boolean,
) => {
// Remove previous status if not first comment
if (!firstComment) {
let removed = false;
Object.values(NoteStatus).forEach((noteStatus) => {
if (!removed && comment.body.toString().startsWith(`[${noteStatus}] `)) {
comment.body = comment.body.toString().slice(noteStatus.length + 3);
removed = true;
}
});
}

// Set new status
comment.body = `[${status}] ${comment.body}`;
Expand Down