From d6a6c4b034cbf3046a7163b3b6de2961cca09770 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Mon, 28 Feb 2022 08:54:40 -0500 Subject: [PATCH] Add back in default keybindings (#4673) * Add back in default keybindings * Add support for edit commands, add in undo --- src/default_config.nu | 7 +++++- src/reedline_config.rs | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/default_config.nu b/src/default_config.nu index 13e93c1097..0fe5ab9660 100644 --- a/src/default_config.nu +++ b/src/default_config.nu @@ -227,7 +227,12 @@ let $config = { modifier: control keycode: char_z mode: emacs # emacs vi_normal vi_insert - event: { send: menupageprevious } + event: { + until: [ + { send: menupageprevious } + { send: edit, cmd: undo } + ] + } } ] } diff --git a/src/reedline_config.rs b/src/reedline_config.rs index 075138d6b6..83d03cfc49 100644 --- a/src/reedline_config.rs +++ b/src/reedline_config.rs @@ -123,6 +123,41 @@ pub(crate) fn add_history_menu(line_editor: Reedline, config: &Config) -> Reedli line_editor.with_menu(Box::new(history_menu)) } +fn add_menu_keybindings(keybindings: &mut Keybindings) { + keybindings.add_binding( + KeyModifiers::CONTROL, + KeyCode::Char('x'), + ReedlineEvent::UntilFound(vec![ + ReedlineEvent::Menu("history_menu".to_string()), + ReedlineEvent::MenuPageNext, + ]), + ); + + keybindings.add_binding( + KeyModifiers::CONTROL, + KeyCode::Char('z'), + ReedlineEvent::UntilFound(vec![ + ReedlineEvent::MenuPagePrevious, + ReedlineEvent::Edit(vec![EditCommand::Undo]), + ]), + ); + + keybindings.add_binding( + KeyModifiers::NONE, + KeyCode::Tab, + ReedlineEvent::UntilFound(vec![ + ReedlineEvent::Menu("completion_menu".to_string()), + ReedlineEvent::MenuNext, + ]), + ); + + keybindings.add_binding( + KeyModifiers::SHIFT, + KeyCode::BackTab, + ReedlineEvent::MenuPrevious, + ); +} + pub enum KeybindingsMode { Emacs(Keybindings), Vi { @@ -137,6 +172,8 @@ pub(crate) fn create_keybindings(config: &Config) -> Result { let mut keybindings = default_emacs_keybindings(); + add_menu_keybindings(&mut keybindings); + for parsed_keybinding in parsed_keybindings { if parsed_keybinding.mode.into_string("", config).as_str() == "emacs" { add_keybinding(&mut keybindings, parsed_keybinding, config)? @@ -149,6 +186,9 @@ pub(crate) fn create_keybindings(config: &Config) -> Result { + let edit_command = parse_edit( + &Value::Record { + cols: cols.to_vec(), + vals: vals.to_vec(), + span: *span, + }, + config, + )?; + Ok(ReedlineEvent::Edit(vec![edit_command])) + } v => Err(ShellError::UnsupportedConfigValue( "Reedline event".to_string(), v.to_string(),