@@ -16,6 +16,7 @@ use helix_view::{
1616};
1717
1818pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
19+type PromptCharHandler = Box<dyn Fn(&mut Prompt, char, &Context)>;
1920
2021pub struct Prompt {
2122 prompt: Cow<'static, str>,
@@ -28,6 +29,7 @@ pub struct Prompt {
2829 completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>,
2930 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
3031 pub doc_fn: Box<dyn Fn(&str) -> Option<Cow<str>>>,
32+ next_char_handler: Option<PromptCharHandler>,
3133}
3234
3335#[derive(Clone, Copy, PartialEq)]
@@ -78,6 +80,7 @@ impl Prompt {
7880 completion_fn: Box::new(completion_fn),
7981 callback_fn: Box::new(callback_fn),
8082 doc_fn: Box::new(|_| None),
83+ next_char_handler: None,
8184 }
8285 }
8386
@@ -191,6 +194,13 @@ impl Prompt {
191194 }
192195
193196 pub fn insert_char(&mut self, c: char, cx: &Context) {
197+ if let Some(handler) = &self.next_char_handler.take() {
198+ handler(self, c, cx);
199+
200+ self.next_char_handler = None;
201+ return;
202+ }
203+
194204 self.line.insert(self.cursor, c);
195205 let mut cursor = GraphemeCursor::new(self.cursor, self.line.len(), false);
196206 if let Ok(Some(pos)) = cursor.next_boundary(&self.line, 0) {
@@ -538,6 +548,35 @@ impl Component for Prompt {
538548 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
539549 }
540550 ctrl!('q') => self.exit_selection(),
551+ ctrl!('r') => {
552+ self.completion = cx
553+ .editor
554+ .registers
555+ .inner()
556+ .iter()
557+ .map(|(ch, reg)| {
558+ let content = reg
559+ .read()
560+ .get(0)
561+ .and_then(|s| s.lines().next().to_owned())
562+ .unwrap_or_default();
563+ (0.., format!("{} {}", ch, &content).into())
564+ })
565+ .collect();
566+ self.next_char_handler = Some(Box::new(|prompt, c, context| {
567+ prompt.insert_str(
568+ context
569+ .editor
570+ .registers
571+ .read(c)
572+ .and_then(|r| r.first())
573+ .map_or("", |r| r.as_str()),
574+ );
575+ prompt.recalculate_completion(context.editor);
576+ }));
577+ (self.callback_fn)(cx, &self.line, PromptEvent::Update);
578+ return EventResult::Consumed(None);
579+ }
541580 // any char event that's not mapped to any other combo
542581 KeyEvent {
543582 code: KeyCode::Char(c),