@@ -8,7 +8,6 @@ import { ImportToolResultsWebview } from './webviews/import-tool-results/importT
88import { ExportNotesWebview } from './webviews/export-notes/exportNotesWebview' ;
99import { commentController } from './controllers/comments' ;
1010import { reactionHandler } from './handlers/reaction' ;
11- import { saveNotesToFileHandler } from './handlers/saveNotesToFile' ;
1211import { getSetting } from './utils' ;
1312import {
1413 saveNoteComment ,
@@ -91,7 +90,7 @@ export function activate(context: vscode.ExtensionContext) {
9190 // save notes to file handler
9291 context . subscriptions . push (
9392 vscode . commands . registerCommand ( 'security-notes.saveNotesToFile' , ( ) =>
94- saveNotesToFileHandler ( noteMap ) ,
93+ saveNotesToFile ( noteMap ) ,
9594 ) ,
9695 ) ;
9796
@@ -125,13 +124,27 @@ export function activate(context: vscode.ExtensionContext) {
125124 return ;
126125 }
127126
127+ let commentRemoved = false ;
128128 thread . comments = thread . comments . filter (
129- ( cmt ) => ( cmt as NoteComment ) . id !== comment . id ,
129+ ( cmt ) => {
130+ const shouldKeep = ( cmt as NoteComment ) . id !== comment . id ;
131+ if ( ! shouldKeep ) {
132+ commentRemoved = true ;
133+ }
134+ return shouldKeep ;
135+ } ,
130136 ) ;
131137
132138 if ( thread . comments . length === 0 ) {
139+ if ( thread . contextValue ) {
140+ noteMap . delete ( thread . contextValue ) ;
141+ }
133142 thread . dispose ( ) ;
134143 }
144+
145+ if ( commentRemoved ) {
146+ saveNotesToFile ( noteMap ) ;
147+ }
135148 } ,
136149 ) ,
137150 ) ;
@@ -144,6 +157,7 @@ export function activate(context: vscode.ExtensionContext) {
144157 thread . dispose ( ) ;
145158 if ( thread . contextValue ) {
146159 noteMap . delete ( thread . contextValue ) ;
160+ saveNotesToFile ( noteMap ) ;
147161 }
148162 } ,
149163 ) ,
@@ -179,17 +193,22 @@ export function activate(context: vscode.ExtensionContext) {
179193 return ;
180194 }
181195
196+ let commentUpdated = false ;
182197 comment . parent . comments = comment . parent . comments . map ( ( cmt ) => {
183198 if ( ( cmt as NoteComment ) . id === comment . id ) {
184199 ( cmt as NoteComment ) . savedBody = cmt . body ;
185200 cmt . mode = vscode . CommentMode . Preview ;
201+ commentUpdated = true ;
186202 }
203+ return cmt ;
204+ } ) ;
187205
188- if ( remoteDb && comment . parent ) {
206+ if ( commentUpdated ) {
207+ saveNotesToFile ( noteMap ) ;
208+ if ( remoteDb ) {
189209 remoteDb . pushNoteComment ( comment . parent , false ) ;
190210 }
191- return cmt ;
192- } ) ;
211+ }
193212 } ,
194213 ) ,
195214 ) ;
0 commit comments