@@ -154,14 +154,25 @@ def __init__(
154154 def compose (self ) -> ComposeResult :
155155 """Compose the sidebar layout."""
156156 self ._option_list = OptionList ()
157- self ._populate_options ()
157+ # Add initial options
158+ item_index = 0
159+ for nav_item in NAV_ITEMS :
160+ if nav_item is None :
161+ self ._option_list .add_option (None ) # None creates a separator
162+ else :
163+ item_index += 1
164+ label = self ._format_label (nav_item , item_index )
165+ self ._option_list .add_option (Option (label , id = nav_item .id ))
158166 yield self ._option_list
159167
160- def _populate_options (self ) -> None :
161- """Populate the OptionList with navigation items ."""
162- if self ._option_list is None :
168+ def _refresh_options (self ) -> None :
169+ """Refresh the OptionList labels (called when display state changes) ."""
170+ if self ._option_list is None or not self . _option_list . is_mounted :
163171 return
164172
173+ # Store current highlighted option
174+ current_highlighted = self ._option_list .highlighted
175+
165176 self ._option_list .clear_options ()
166177 item_index = 0
167178
@@ -173,6 +184,10 @@ def _populate_options(self) -> None:
173184 label = self ._format_label (nav_item , item_index )
174185 self ._option_list .add_option (Option (label , id = nav_item .id ))
175186
187+ # Restore highlighted index
188+ if current_highlighted is not None :
189+ self ._option_list .highlighted = current_highlighted
190+
176191 def _format_label (self , item : NavItem , index : int ) -> Text :
177192 """Format a navigation item label.
178193
@@ -227,7 +242,7 @@ def watch_collapsed(self, collapsed: bool) -> None:
227242 self .remove_class ("-collapsed" )
228243
229244 # Re-render labels
230- self ._populate_options ()
245+ self ._refresh_options ()
231246
232247 def set_active_item (self , item_id : str ) -> None :
233248 """Set the active (highlighted) navigation item.
@@ -252,7 +267,7 @@ def set_triage_count(self, count: int) -> None:
252267 """
253268 self .triage_count = count
254269 # Re-render to update badge
255- self ._populate_options ()
270+ self ._refresh_options ()
256271
257272 def _select_by_index (self , index : int ) -> None :
258273 """Select a navigation item by its 1-based index.
0 commit comments