Sort keystuff (#945)

* sort things

* reorg
This commit is contained in:
Darren Schroeder 2022-02-04 17:20:54 -06:00 committed by GitHub
parent abaeffab91
commit 709927cee4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -80,11 +80,11 @@ impl Command for ListKeybindings {
fn get_records(entry_type: &str, span: &Span) -> Vec<Value> { fn get_records(entry_type: &str, span: &Span) -> Vec<Value> {
let values = match entry_type { let values = match entry_type {
"modifiers" => get_reedline_keybinding_modifiers(), "modifiers" => get_reedline_keybinding_modifiers().sorted(),
"keycodes" => get_reedline_keycodes(), "keycodes" => get_reedline_keycodes().sorted(),
"edits" => get_reedline_edit_commands(), "edits" => get_reedline_edit_commands().sorted(),
"modes" => get_reedline_prompt_edit_modes(), "modes" => get_reedline_prompt_edit_modes().sorted(),
"events" => get_reedline_reedline_events(), "events" => get_reedline_reedline_events().sorted(),
_ => Vec::new(), _ => Vec::new(),
}; };
@ -112,3 +112,18 @@ fn convert_to_record(edit: &str, entry_type: &str, span: &Span) -> Value {
span: *span, span: *span,
} }
} }
// Helper to sort a vec and return a vec
trait SortedImpl {
fn sorted(self) -> Self;
}
impl<E> SortedImpl for Vec<E>
where
E: std::cmp::Ord,
{
fn sorted(mut self) -> Self {
self.sort();
self
}
}