@@ -13,6 +13,11 @@ class GraphLoadSave extends GraphUndoRedo {
1313 constructor ( ...args ) {
1414 super ( ...args ) ;
1515 this . autoSaveIntervalId = null ;
16+ this . lastSavedActionIndex = 0 ;
17+ }
18+
19+ get isSaved ( ) {
20+ return this . curActionIndex === this . lastSavedActionIndex ;
1621 }
1722
1823 registerEvents ( ) {
@@ -132,6 +137,7 @@ class GraphLoadSave extends GraphUndoRedo {
132137 fileHandle : handle ,
133138 } ] ) ;
134139 this . dispatcher ( { type : T . SET_FILE_STATE , payload : fS } ) ;
140+ this . lastSavedActionIndex = this . curActionIndex ;
135141 toast . success ( 'File saved Successfully' ) ;
136142 } catch ( error ) {
137143 // AbortError is silently ignored (user cancelled)
@@ -140,6 +146,7 @@ class GraphLoadSave extends GraphUndoRedo {
140146 // eslint-disable-next-line no-alert
141147 const fileName = prompt ( 'Filename:' ) ;
142148 saveAs ( blob , `${ fileName || `${ this . getName ( ) } -concore` } .graphml` ) ;
149+ this . lastSavedActionIndex = this . curActionIndex ;
143150 toast . success ( 'File saved Successfully' ) ;
144151 }
145152 }
@@ -172,6 +179,7 @@ class GraphLoadSave extends GraphUndoRedo {
172179 const stream = await handle . createWritable ( ) ;
173180 await stream . write ( blob ) ;
174181 await stream . close ( ) ;
182+ this . lastSavedActionIndex = this . curActionIndex ;
175183 toast . success ( 'File saved Successfully' ) ;
176184 } catch ( error ) {
177185 // AbortError is silently ignored (user cancelled)
@@ -213,6 +221,7 @@ class GraphLoadSave extends GraphUndoRedo {
213221 graphMLParser ( graphML ) . then ( ( graphObject ) => {
214222 localStorageManager . save ( this . id , graphObject ) ;
215223 this . loadGraphFromLocalStorage ( ) ;
224+ this . lastSavedActionIndex = this . curActionIndex ;
216225 } ) ;
217226 }
218227
@@ -225,6 +234,10 @@ class GraphLoadSave extends GraphUndoRedo {
225234 const graphContent = localStorageManager . get ( this . id ) ;
226235 if ( ! graphContent ) return false ;
227236 this . loadJson ( graphContent ) ;
237+ // If loaded from localStorage, assume UNSAVED unless actions are 0.
238+ // Actually, loadJson sets curActionIndex based on history.
239+ // If we want to support recovering unsaved work, we should leave lastSavedActionIndex as 0 (unless graph is empty and curActionIndex is 0).
240+ if ( this . curActionIndex === 0 ) this . lastSavedActionIndex = 0 ;
228241 return true ;
229242 }
230243
0 commit comments