@@ -272,12 +272,14 @@ export class AnnotationListToolboxItem extends ToolboxItem {
272272 // Show/hide deprecated annotations checkbox
273273 $ ( document ) . on ( "change.ulabel" , "#annotation-list-show-deprecated" , ( e ) => {
274274 this . show_deprecated = ( e . target as HTMLInputElement ) . checked ;
275+ set_local_storage_item ( "ulabel_annotation_list_show_deprecated" , this . show_deprecated ? "true" : "false" ) ;
275276 this . update_list ( ) ;
276277 } ) ;
277278
278279 // Group by class checkbox
279280 $ ( document ) . on ( "change.ulabel" , "#annotation-list-group-by-class" , ( e ) => {
280281 this . group_by_class = ( e . target as HTMLInputElement ) . checked ;
282+ set_local_storage_item ( "ulabel_annotation_list_group_by_class" , this . group_by_class ? "true" : "false" ) ;
281283 this . update_list ( ) ;
282284 } ) ;
283285
@@ -448,11 +450,30 @@ export class AnnotationListToolboxItem extends ToolboxItem {
448450 groups [ class_id ] . push ( annotation ) ;
449451 }
450452
453+ // Build the render order: first walk class_defs in declared order so the
454+ // group headers appear in the same order as the AnnotationIDToolboxItem.
455+ // Then append any orphan class_ids (not in class_defs) as a defensive
456+ // fallback so we never silently drop annotations.
457+ const ordered_class_ids : number [ ] = [ ] ;
458+ const seen_class_ids : Set < number > = new Set ( ) ;
459+ for ( const def of subtask . class_defs ) {
460+ if ( groups [ def . id ] ) {
461+ ordered_class_ids . push ( def . id ) ;
462+ seen_class_ids . add ( def . id ) ;
463+ }
464+ }
465+ const orphan_class_ids = Object . keys ( groups )
466+ . map ( ( id_str ) => parseInt ( id_str ) )
467+ . filter ( ( id ) => ! seen_class_ids . has ( id ) )
468+ . sort ( ( a , b ) => a - b ) ;
469+ for ( const id of orphan_class_ids ) {
470+ ordered_class_ids . push ( id ) ;
471+ }
472+
451473 // Build HTML for each group
452474 let html = "" ;
453475
454- for ( const class_id_str in groups ) {
455- const class_id = parseInt ( class_id_str ) ;
476+ for ( const class_id of ordered_class_ids ) {
456477 const group_annotations = groups [ class_id ] ;
457478 const class_def = subtask . class_defs . find ( ( def ) => def . id === class_id ) ;
458479 const class_name = class_def ? class_def . name : "Unknown" ;
@@ -604,23 +625,43 @@ export class AnnotationListToolboxItem extends ToolboxItem {
604625 * Code called after all of ULabel's constructor and initialization code is called
605626 */
606627 public after_init ( ) : void {
607- // Restore collapsed state from localStorage
608- this . restore_collapsed_state ( ) ;
628+ // Restore persisted UI state from localStorage
629+ this . restore_persisted_state ( ) ;
609630
610631 // Initial list update
611632 this . update_list ( ) ;
612633 }
613634
614635 /**
615- * Restore the collapsed state from localStorage
636+ * Restore persisted UI state (collapsed flag + checkbox toggles) from localStorage.
616637 */
617- private restore_collapsed_state ( ) : void {
618- const stored_state = get_local_storage_item ( "ulabel_annotation_list_collapsed" ) ;
619- if ( stored_state === "false" ) {
638+ private restore_persisted_state ( ) : void {
639+ const stored_collapsed = get_local_storage_item ( "ulabel_annotation_list_collapsed" ) ;
640+ if ( stored_collapsed === "false" ) {
620641 this . is_collapsed = false ;
621- } else if ( stored_state === "true" ) {
642+ } else if ( stored_collapsed === "true" ) {
622643 this . is_collapsed = true ;
623644 }
645+
646+ const stored_show_deprecated = get_local_storage_item ( "ulabel_annotation_list_show_deprecated" ) ;
647+ if ( stored_show_deprecated === "true" ) {
648+ this . show_deprecated = true ;
649+ } else if ( stored_show_deprecated === "false" ) {
650+ this . show_deprecated = false ;
651+ }
652+
653+ const stored_group_by_class = get_local_storage_item ( "ulabel_annotation_list_group_by_class" ) ;
654+ if ( stored_group_by_class === "true" ) {
655+ this . group_by_class = true ;
656+ } else if ( stored_group_by_class === "false" ) {
657+ this . group_by_class = false ;
658+ }
659+
660+ // Reflect restored values into the checkbox DOM so the UI matches state.
661+ const show_deprecated_input = document . querySelector < HTMLInputElement > ( "#annotation-list-show-deprecated" ) ;
662+ if ( show_deprecated_input ) show_deprecated_input . checked = this . show_deprecated ;
663+ const group_by_class_input = document . querySelector < HTMLInputElement > ( "#annotation-list-group-by-class" ) ;
664+ if ( group_by_class_input ) group_by_class_input . checked = this . group_by_class ;
624665 }
625666
626667 /**
0 commit comments