diff --git a/book/src/keymap.md b/book/src/keymap.md index 9d5d08417..e56eeefc4 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -367,6 +367,7 @@ Keys to use within prompt, Remapping currently not supported. | `Ctrl-s` | Insert a word under doc cursor, may be changed to Ctrl-r Ctrl-w later | | `Ctrl-p`, `Up` | Select previous history | | `Ctrl-n`, `Down` | Select next history | +| `Ctrl-r` | Insert the content of the register selected by following input char | | `Tab` | Select next completion item | | `BackTab` | Select previous completion item | | `Enter` | Open selected | diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index ef08edf2d..b971885a9 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -28,6 +28,7 @@ pub struct Prompt { completion_fn: Box Vec>, callback_fn: Box, pub doc_fn: Box Option>>, + selecting_register: bool, } #[derive(Clone, Copy, PartialEq)] @@ -78,6 +79,7 @@ impl Prompt { completion_fn: Box::new(completion_fn), callback_fn: Box::new(callback_fn), doc_fn: Box::new(|_| None), + selecting_register: false, } } @@ -538,17 +540,33 @@ impl Component for Prompt { (self.callback_fn)(cx, &self.line, PromptEvent::Update) } ctrl!('q') => self.exit_selection(), + ctrl!('r') => { + self.selecting_register = true; + (self.callback_fn)(cx, &self.line, PromptEvent::Update); + return EventResult::Consumed(None); + } // any char event that's not mapped to any other combo KeyEvent { code: KeyCode::Char(c), modifiers: _, } => { - self.insert_char(c, cx); + if self.selecting_register { + self.insert_str( + cx.editor + .registers + .read(c) + .and_then(|r| r.first()) + .map_or("", |r| r.as_str()), + ); + } else { + self.insert_char(c, cx); + } (self.callback_fn)(cx, &self.line, PromptEvent::Update); } _ => (), }; + self.selecting_register = false; EventResult::Consumed(None) }