@@ -272,9 +272,9 @@ export default class CommentatorPlugin extends Plugin {
272272 }
273273
274274 async migrateSettings ( new_settings : PluginSettings ) {
275- const old_settings = this . settings ;
275+ const original_settings = this . settings ;
276276 this . settings = Object . assign ( { } , DEFAULT_SETTINGS , new_settings ) ;
277- this . previous_settings = Object . assign ( old_settings , this . settings ) ;
277+ this . previous_settings = Object . assign ( { } , original_settings , this . settings ) ;
278278 COMMENTATOR_GLOBAL . PLUGIN_SETTINGS = this . settings ;
279279
280280 // EXPL: Do not migrate new installs, immediately save settings
@@ -285,6 +285,7 @@ export default class CommentatorPlugin extends Plugin {
285285 // EXPL: Migration code for upgrading to a new version
286286 try {
287287 if ( old_version !== DEFAULT_SETTINGS . version ) {
288+ // EXPL: Migrate settings from 0.1.x, where the settings did not contain a version field
288289 if ( ! old_version ) {
289290 this . app . workspace . onLayoutReady ( async ( ) => {
290291 new Notice ( "Commentator: rebuilding database for new version" , 5000 ) ;
@@ -293,19 +294,37 @@ export default class CommentatorPlugin extends Plugin {
293294 0 ,
294295 ) ;
295296 } ) ;
296- } else if ( old_version . localeCompare ( "0.2.2" , undefined , { numeric : true } ) < 0 ) {
297+ }
298+
299+ // EXPL: Migrate settings from 0.2.x to 0.2.3, suggestion and comment gutter settings were renamed
300+ if ( old_version . localeCompare ( "0.2.3" , undefined , { numeric : true } ) < 0 ) {
297301 if ( ( new_settings as any ) . suggestion_gutter_hide_empty ) {
298- this . settings . diff_gutter = ( new_settings as any ) . suggestion_gutter ;
299- this . settings . diff_gutter_hide_empty = ( new_settings as any ) . suggestion_gutter_hide_empty ;
300-
301- this . settings . annotation_gutter = ( new_settings as any ) . comment_style === "block" ;
302- this . settings . annotation_gutter_default_fold_state = ( new_settings as any ) . comment_gutter_default_fold_state ;
303- this . settings . annotation_gutter_fold_button = ( new_settings as any ) . comment_gutter_fold_button ;
304- this . settings . annotation_gutter_resize_handle = ( new_settings as any ) . comment_gutter_resize_handle ;
305- this . settings . annotation_gutter_width = ( new_settings as any ) . comment_gutter_width ;
306- this . settings . annotation_gutter_hide_empty = ( new_settings as any ) . comment_gutter_hide_empty ;
302+ const settings_migrations = [
303+ [ "suggestion_gutter" , "diff_gutter" ] ,
304+ [ "suggestion_gutter_hide_empty" , "diff_gutter_hide_empty" ] ,
305+
306+ [ "comment_gutter_default_fold_state" , "annotation_gutter_default_fold_state" ] ,
307+ [ "comment_gutter_fold_button" , "annotation_gutter_fold_button" ] ,
308+ [ "comment_gutter_resize_handle" , "annotation_gutter_resize_handle" ] ,
309+ [ "comment_gutter_width" , "annotation_gutter_width" ] ,
310+ [ "comment_gutter_hide_empty" , "annotation_gutter_hide_empty" ] ,
311+ ] as ( keyof typeof new_settings ) [ ] [ ] ;
312+
313+ for ( const [ old_key , new_key ] of settings_migrations ) {
314+ if ( old_key in this . settings ) {
315+ ( this . settings as unknown as any ) [ new_key ] = this . settings [ old_key ] ;
316+ delete this . settings [ old_key ] ;
317+ }
318+ }
319+
320+ if ( this . settings . comment_style as any === "block" ) {
321+ this . settings . comment_style = "icon" ;
322+ this . settings . annotation_gutter = true ;
323+ }
307324 }
308325 }
326+
327+ this . settings . version = DEFAULT_SETTINGS . version ;
309328 await this . setSettings ( ) ;
310329 }
311330 } catch ( e ) {
0 commit comments