@@ -512,7 +512,11 @@ impl IdeMenu {
512
512
} ;
513
513
514
514
if use_ansi_coloring {
515
- let match_len = self . working_details . shortest_base_string . len ( ) ;
515
+ let match_len = self
516
+ . working_details
517
+ . shortest_base_string
518
+ . len ( )
519
+ . min ( string. len ( ) ) ;
516
520
517
521
// Split string so the match text can be styled
518
522
let ( match_str, remaining_str) = string. split_at ( match_len) ;
@@ -1401,4 +1405,40 @@ mod tests {
1401
1405
"cursor should be at the end after completion"
1402
1406
) ;
1403
1407
}
1408
+
1409
+ #[ test]
1410
+ fn test_regression_panic_on_long_item ( ) {
1411
+ let commands = vec ! [
1412
+ "hello world 2" . into( ) ,
1413
+ "hello another very large option for hello word that will force one column" . into( ) ,
1414
+ "this is the reedline crate" . into( ) ,
1415
+ "abaaabas" . into( ) ,
1416
+ "abaaacas" . into( ) ,
1417
+ ] ;
1418
+
1419
+ let mut completer = Box :: new ( crate :: DefaultCompleter :: new_with_wordlen ( commands, 2 ) ) ;
1420
+
1421
+ let mut menu = IdeMenu :: default ( ) . with_name ( "testmenu" ) ;
1422
+ menu. working_details = IdeMenuDetails {
1423
+ cursor_col : 50 ,
1424
+ menu_width : 50 ,
1425
+ completion_width : 50 ,
1426
+ description_width : 50 ,
1427
+ description_is_right : true ,
1428
+ space_left : 50 ,
1429
+ space_right : 50 ,
1430
+ description_offset : 50 ,
1431
+ shortest_base_string : String :: new ( ) ,
1432
+ } ;
1433
+ let mut editor = Editor :: default ( ) ;
1434
+ // backtick at the end of the line
1435
+ editor. set_buffer (
1436
+ "hello another very large option for hello word that will force one colu" . to_string ( ) ,
1437
+ UndoBehavior :: CreateUndoPoint ,
1438
+ ) ;
1439
+
1440
+ menu. update_values ( & mut editor, & mut * completer) ;
1441
+
1442
+ menu. menu_string ( 500 , true ) ;
1443
+ }
1404
1444
}
0 commit comments