diff options
author | Bob | 2022-07-18 01:17:13 +0000 |
---|---|---|
committer | GitHub | 2022-07-18 01:17:13 +0000 |
commit | e5c7aaed91c0b3d533a04840fedb88ecabc8f6a8 (patch) | |
tree | 7b615802e6a9a49faa58e34cf43db3fa7a0606f0 /helix-term/src/ui/mod.rs | |
parent | 55b45ec4a4cb958b241a93cc7c3f4e499379890e (diff) |
support prefilling prompt (#2459)
* support prefilling prompt
* introduce with_line builder method in Prompt
* extract show_prompt
* use textobject_word as fallback input
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r-- | helix-term/src/ui/mod.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index c7d409e9..88a226e9 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -34,7 +34,27 @@ pub fn prompt( completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static, callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static, ) { - let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn); + show_prompt( + cx, + Prompt::new(prompt, history_register, completion_fn, callback_fn), + ); +} + +pub fn prompt_with_input( + cx: &mut crate::commands::Context, + prompt: std::borrow::Cow<'static, str>, + input: String, + history_register: Option<char>, + completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static, + callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static, +) { + show_prompt( + cx, + Prompt::new(prompt, history_register, completion_fn, callback_fn).with_line(input), + ); +} + +fn show_prompt(cx: &mut crate::commands::Context, mut prompt: Prompt) { // Calculate initial completion prompt.recalculate_completion(cx.editor); cx.push_layer(Box::new(prompt)); |