Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/menu/ide_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,11 @@ impl IdeMenu {
};

if use_ansi_coloring {
let match_len = self.working_details.shortest_base_string.len();
let match_len = self
.working_details
.shortest_base_string
.len()
.min(string.len());

// Split string so the match text can be styled
let (match_str, remaining_str) = string.split_at(match_len);
Expand Down Expand Up @@ -1401,4 +1405,40 @@ mod tests {
"cursor should be at the end after completion"
);
}

#[test]
fn test_regression_panic_on_long_item() {
let commands = vec![
"hello world 2".into(),
"hello another very large option for hello word that will force one column".into(),
"this is the reedline crate".into(),
"abaaabas".into(),
"abaaacas".into(),
];

let mut completer = Box::new(crate::DefaultCompleter::new_with_wordlen(commands, 2));

let mut menu = IdeMenu::default().with_name("testmenu");
menu.working_details = IdeMenuDetails {
cursor_col: 50,
menu_width: 50,
completion_width: 50,
description_width: 50,
description_is_right: true,
space_left: 50,
space_right: 50,
description_offset: 50,
shortest_base_string: String::new(),
};
let mut editor = Editor::default();
// backtick at the end of the line
editor.set_buffer(
"hello another very large option for hello word that will force one colu".to_string(),
UndoBehavior::CreateUndoPoint,
);

menu.update_values(&mut editor, &mut *completer);

menu.menu_string(500, true);
}
}
Loading