File tree Expand file tree Collapse file tree
src/cortex-tui/src/widgets/help_browser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -152,7 +152,9 @@ impl<'a> HelpBrowser<'a> {
152152
153153 /// Renders the content pane.
154154 fn render_content ( & self , area : Rect , buf : & mut Buffer ) {
155- let section = self . state . current_section ( ) ;
155+ let Some ( section) = self . state . current_section ( ) else {
156+ return ;
157+ } ;
156158 let mut y = area. y ;
157159 let scroll = self . state . content_scroll ;
158160 let mut line_idx = 0 ;
Original file line number Diff line number Diff line change @@ -148,8 +148,13 @@ impl HelpBrowserState {
148148 }
149149
150150 /// Returns the currently selected section.
151- pub fn current_section ( & self ) -> & HelpSection {
152- & self . sections [ self . selected_section ]
151+ ///
152+ /// Returns `None` if the sections vector is empty.
153+ pub fn current_section ( & self ) -> Option < & HelpSection > {
154+ if self . sections . is_empty ( ) {
155+ return None ;
156+ }
157+ self . sections . get ( self . selected_section )
153158 }
154159
155160 /// Handles character input for search.
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ mod tests {
4343 #[ test]
4444 fn test_help_browser_state_with_topic ( ) {
4545 let state = HelpBrowserState :: new ( ) . with_topic ( Some ( "keyboard" ) ) ;
46- assert_eq ! ( state. current_section( ) . id, "keyboard" ) ;
46+ assert_eq ! ( state. current_section( ) . expect ( "should have section" ) . id, "keyboard" ) ;
4747 }
4848
4949 #[ test]
@@ -220,10 +220,10 @@ mod tests {
220220 #[ test]
221221 fn test_current_section ( ) {
222222 let mut state = HelpBrowserState :: new ( ) ;
223- assert_eq ! ( state. current_section( ) . id, "getting-started" ) ;
223+ assert_eq ! ( state. current_section( ) . expect ( "should have section" ) . id, "getting-started" ) ;
224224
225225 state. select_next ( ) ;
226- assert_eq ! ( state. current_section( ) . id, "keyboard" ) ;
226+ assert_eq ! ( state. current_section( ) . expect ( "should have section" ) . id, "keyboard" ) ;
227227 }
228228
229229 #[ test]
@@ -232,4 +232,11 @@ mod tests {
232232 assert ! ( !state. sections. is_empty( ) ) ;
233233 assert_eq ! ( state. selected_section, 0 ) ;
234234 }
235- }
235+
236+ #[ test]
237+ fn test_current_section_empty_sections ( ) {
238+ let mut state = HelpBrowserState :: new ( ) ;
239+ state. sections . clear ( ) ;
240+ assert ! ( state. current_section( ) . is_none( ) ) ;
241+ }
242+ }
You can’t perform that action at this time.
0 commit comments