From 709927cee4ae7eca056dcc62150d6b4f8d9eaa1b Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 4 Feb 2022 17:20:54 -0600 Subject: [PATCH] Sort keystuff (#945) * sort things * reorg --- .../reedline_commands/list_keybindings.rs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/nu-command/src/platform/reedline_commands/list_keybindings.rs b/crates/nu-command/src/platform/reedline_commands/list_keybindings.rs index d1d9760b01..546601b0fc 100644 --- a/crates/nu-command/src/platform/reedline_commands/list_keybindings.rs +++ b/crates/nu-command/src/platform/reedline_commands/list_keybindings.rs @@ -80,11 +80,11 @@ impl Command for ListKeybindings { fn get_records(entry_type: &str, span: &Span) -> Vec { let values = match entry_type { - "modifiers" => get_reedline_keybinding_modifiers(), - "keycodes" => get_reedline_keycodes(), - "edits" => get_reedline_edit_commands(), - "modes" => get_reedline_prompt_edit_modes(), - "events" => get_reedline_reedline_events(), + "modifiers" => get_reedline_keybinding_modifiers().sorted(), + "keycodes" => get_reedline_keycodes().sorted(), + "edits" => get_reedline_edit_commands().sorted(), + "modes" => get_reedline_prompt_edit_modes().sorted(), + "events" => get_reedline_reedline_events().sorted(), _ => Vec::new(), }; @@ -112,3 +112,18 @@ fn convert_to_record(edit: &str, entry_type: &str, span: &Span) -> Value { span: *span, } } + +// Helper to sort a vec and return a vec +trait SortedImpl { + fn sorted(self) -> Self; +} + +impl SortedImpl for Vec +where + E: std::cmp::Ord, +{ + fn sorted(mut self) -> Self { + self.sort(); + self + } +}