diff options
author | Blaž Hrastnik | 2022-03-22 05:32:06 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-03-28 02:02:13 +0000 |
commit | 5c162ef995e3822cd465f2c83874a040ebe153b8 (patch) | |
tree | ff0a923b235e96d8c677e97fa2690454bc7f16f8 | |
parent | 83b3272166013a7c394fb41dca172042e3229ab4 (diff) |
Make regex_prompt directly call cx.push_layer
-rw-r--r-- | helix-term/src/commands.rs | 22 | ||||
-rw-r--r-- | helix-term/src/compositor.rs | 8 | ||||
-rw-r--r-- | helix-term/src/ui/mod.rs | 5 |
3 files changed, 9 insertions, 26 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 3c954ee5..7de4d7eb 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1411,7 +1411,7 @@ fn select_all(cx: &mut Context) { fn select_regex(cx: &mut Context) { let reg = cx.register.unwrap_or('/'); - let prompt = ui::regex_prompt( + ui::regex_prompt( cx, "select:".into(), Some(reg), @@ -1428,13 +1428,11 @@ fn select_regex(cx: &mut Context) { } }, ); - - cx.push_layer(Box::new(prompt)); } fn split_selection(cx: &mut Context) { let reg = cx.register.unwrap_or('/'); - let prompt = ui::regex_prompt( + ui::regex_prompt( cx, "split:".into(), Some(reg), @@ -1448,8 +1446,6 @@ fn split_selection(cx: &mut Context) { doc.set_selection(view.id, selection); }, ); - - cx.push_layer(Box::new(prompt)); } fn split_selection_on_newline(cx: &mut Context) { @@ -1578,7 +1574,7 @@ fn searcher(cx: &mut Context, direction: Direction) { let contents = doc.text().slice(..).to_string(); let completions = search_completions(cx, Some(reg)); - let prompt = ui::regex_prompt( + ui::regex_prompt( cx, "search:".into(), Some(reg), @@ -1605,8 +1601,6 @@ fn searcher(cx: &mut Context, direction: Direction) { ); }, ); - - cx.push_layer(Box::new(prompt)); } fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) { @@ -1682,7 +1676,7 @@ fn global_search(cx: &mut Context) { let file_picker_config = config.file_picker.clone(); let completions = search_completions(cx, None); - let prompt = ui::regex_prompt( + ui::regex_prompt( cx, "global-search:".into(), None, @@ -1764,8 +1758,6 @@ fn global_search(cx: &mut Context) { }, ); - cx.push_layer(Box::new(prompt)); - let current_path = doc_mut!(cx.editor).path().cloned(); let show_picker = async move { @@ -3400,7 +3392,7 @@ fn join_selections(cx: &mut Context) { fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) { // keep or remove selections matching regex let reg = cx.register.unwrap_or('/'); - let prompt = ui::regex_prompt( + ui::regex_prompt( cx, if remove { "remove:" } else { "keep:" }.into(), Some(reg), @@ -3417,9 +3409,7 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) { doc.set_selection(view.id, selection); } }, - ); - - cx.push_layer(Box::new(prompt)); + ) } fn keep_selections(cx: &mut Context) { diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 4f988ace..e3cec643 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -9,14 +9,6 @@ use tui::buffer::Buffer as Surface; pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>; -// --> EventResult should have a callback that takes a context with methods like .popup(), -// .prompt() etc. That way we can abstract it from the renderer. -// Q: How does this interact with popups where we need to be able to specify the rendering of the -// popup? -// A: It could just take a textarea. -// -// If Compositor was specified in the callback that's then problematic because of - // Cursive-inspired pub enum EventResult { Ignored(Option<Callback>), diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 6242ea2e..3c39a517 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -32,7 +32,7 @@ pub fn regex_prompt( history_register: Option<char>, completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static, fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static, -) -> Prompt { +) { let (view, doc) = current!(cx.editor); let doc_id = view.doc; let snapshot = doc.selection(view.id).clone(); @@ -95,7 +95,8 @@ pub fn regex_prompt( ); // Calculate initial completion prompt.recalculate_completion(cx.editor); - prompt + // prompt + cx.push_layer(Box::new(prompt)); } pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> { |