Skip to content

Commit 7af8959

Browse files
authored
Fix panic in long item completion in ide menu (#823)
1 parent 020142f commit 7af8959

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/menu/ide_menu.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,11 @@ impl IdeMenu {
512512
};
513513

514514
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());
516520

517521
// Split string so the match text can be styled
518522
let (match_str, remaining_str) = string.split_at(match_len);
@@ -1401,4 +1405,40 @@ mod tests {
14011405
"cursor should be at the end after completion"
14021406
);
14031407
}
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+
}
14041444
}

0 commit comments

Comments
 (0)