From 3d41792b5a867a29249a47b8bc3c9d4bc116a5c6 Mon Sep 17 00:00:00 2001 From: Jason Fields Date: Fri, 1 Apr 2022 22:25:41 -0400 Subject: [PATCH] Basic support for C-r to paste register in prompt Refs #1512 --- helix-term/src/ui/prompt.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 4daa33e5468ff..a13f38c66d2e6 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -1,6 +1,7 @@ use crate::compositor::{Component, Compositor, Context, EventResult}; use crate::{alt, ctrl, key, shift, ui}; use crossterm::event::Event; +use helix_view::info::Info; use helix_view::input::KeyEvent; use helix_view::keyboard::{KeyCode, KeyModifiers}; use std::{borrow::Cow, ops::RangeFrom}; @@ -25,6 +26,7 @@ pub struct Prompt { selection: Option, history_register: Option, history_pos: Option, + pending_register: bool, completion_fn: Box Vec>, callback_fn: Box, pub doc_fn: Box Option>>, @@ -71,6 +73,7 @@ impl Prompt { selection: None, history_register, history_pos: None, + pending_register: false, completion_fn: Box::new(completion_fn), callback_fn: Box::new(callback_fn), doc_fn: Box::new(|_| None), @@ -450,6 +453,27 @@ impl Component for Prompt { compositor.pop(); }))); + if self.pending_register { + // C-r was pressed previously; this keystroke is the register + self.pending_register = false; + cx.editor.autoinfo = None; + + match event.into() { + KeyEvent { + code: KeyCode::Char(register), + modifiers: KeyModifiers::NONE, + } => { + if let Some(text) = cx.editor.registers.get(register) { + self.insert_str(&text.read()[0]) + } + } + _ => {} + } + + (self.callback_fn)(cx, &self.line, PromptEvent::Update); + return EventResult::Consumed(None); + } + match event.into() { ctrl!('c') | key!(Esc) => { (self.callback_fn)(cx, &self.line, PromptEvent::Abort); @@ -528,6 +552,11 @@ impl Component for Prompt { self.change_completion_selection(CompletionDirection::Backward); (self.callback_fn)(cx, &self.line, PromptEvent::Update) } + ctrl!('r') => { + cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); + self.pending_register = true; + (self.callback_fn)(cx, &self.line, PromptEvent::Update) + } ctrl!('q') => self.exit_selection(), // any char event that's not combined with control or mapped to any other combo KeyEvent {