on master help sign in
Make regex_prompt directly call cx.push_layer
5c162efBlaž Hrastnik
helix-term/src/commands.rs+6−16
@@ -1411,7 +1411,7 @@ fn select_all(cx: &mut Context) {
1411
1411
1412fn select_regex(cx: &mut Context) {
1412fn select_regex(cx: &mut Context) {
1413 let reg = cx.register.unwrap_or('/');
1413 let reg = cx.register.unwrap_or('/');
1414− let prompt = ui::regex_prompt(
1414+ ui::regex_prompt(
1415 cx,
1415 cx,
1416 "select:".into(),
1416 "select:".into(),
1417 Some(reg),
1417 Some(reg),
@@ -1428,13 +1428,11 @@ fn select_regex(cx: &mut Context) {
1428 }
1428 }
1429 },
1429 },
1430 );
1430 );
1431−
1432− cx.push_layer(Box::new(prompt));
1433}
1431}
1434
1432
1435fn split_selection(cx: &mut Context) {
1433fn split_selection(cx: &mut Context) {
1436 let reg = cx.register.unwrap_or('/');
1434 let reg = cx.register.unwrap_or('/');
1437− let prompt = ui::regex_prompt(
1435+ ui::regex_prompt(
1438 cx,
1436 cx,
1439 "split:".into(),
1437 "split:".into(),
1440 Some(reg),
1438 Some(reg),
@@ -1448,8 +1446,6 @@ fn split_selection(cx: &mut Context) {
1448 doc.set_selection(view.id, selection);
1446 doc.set_selection(view.id, selection);
1449 },
1447 },
1450 );
1448 );
1451−
1452− cx.push_layer(Box::new(prompt));
1453}
1449}
1454
1450
1455fn split_selection_on_newline(cx: &mut Context) {
1451fn split_selection_on_newline(cx: &mut Context) {
@@ -1578,7 +1574,7 @@ fn searcher(cx: &mut Context, direction: Direction) {
1578 let contents = doc.text().slice(..).to_string();
1574 let contents = doc.text().slice(..).to_string();
1579 let completions = search_completions(cx, Some(reg));
1575 let completions = search_completions(cx, Some(reg));
1580
1576
1581− let prompt = ui::regex_prompt(
1577+ ui::regex_prompt(
1582 cx,
1578 cx,
1583 "search:".into(),
1579 "search:".into(),
1584 Some(reg),
1580 Some(reg),
@@ -1605,8 +1601,6 @@ fn searcher(cx: &mut Context, direction: Direction) {
1605 );
1601 );
1606 },
1602 },
1607 );
1603 );
1608−
1609− cx.push_layer(Box::new(prompt));
1610}
1604}
1611
1605
1612fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) {
1606fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Direction) {
@@ -1682,7 +1676,7 @@ fn global_search(cx: &mut Context) {
1682 let file_picker_config = config.file_picker.clone();
1676 let file_picker_config = config.file_picker.clone();
1683
1677
1684 let completions = search_completions(cx, None);
1678 let completions = search_completions(cx, None);
1685− let prompt = ui::regex_prompt(
1679+ ui::regex_prompt(
1686 cx,
1680 cx,
1687 "global-search:".into(),
1681 "global-search:".into(),
1688 None,
1682 None,
@@ -1764,8 +1758,6 @@ fn global_search(cx: &mut Context) {
1764 },
1758 },
1765 );
1759 );
1766
1760
1767− cx.push_layer(Box::new(prompt));
1768−
1769 let current_path = doc_mut!(cx.editor).path().cloned();
1761 let current_path = doc_mut!(cx.editor).path().cloned();
1770
1762
1771 let show_picker = async move {
1763 let show_picker = async move {
@@ -3400,7 +3392,7 @@ fn join_selections(cx: &mut Context) {
3400fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3392fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3401 // keep or remove selections matching regex
3393 // keep or remove selections matching regex
3402 let reg = cx.register.unwrap_or('/');
3394 let reg = cx.register.unwrap_or('/');
3403− let prompt = ui::regex_prompt(
3395+ ui::regex_prompt(
3404 cx,
3396 cx,
3405 if remove { "remove:" } else { "keep:" }.into(),
3397 if remove { "remove:" } else { "keep:" }.into(),
3406 Some(reg),
3398 Some(reg),
@@ -3417,9 +3409,7 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3417 doc.set_selection(view.id, selection);
3409 doc.set_selection(view.id, selection);
3418 }
3410 }
3419 },
3411 },
3420− );
3412+ )
3421−
3422− cx.push_layer(Box::new(prompt));
3423}
3413}
3424
3414
3425fn keep_selections(cx: &mut Context) {
3415fn keep_selections(cx: &mut Context) {
helix-term/src/compositor.rs−8
@@ -9,14 +9,6 @@ use tui::buffer::Buffer as Surface;
9
9
10pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
10pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
11
11
12−// --> EventResult should have a callback that takes a context with methods like .popup(),
13−// .prompt() etc. That way we can abstract it from the renderer.
14−// Q: How does this interact with popups where we need to be able to specify the rendering of the
15−// popup?
16−// A: It could just take a textarea.
17−//
18−// If Compositor was specified in the callback that's then problematic because of
19−
20// Cursive-inspired
12// Cursive-inspired
21pub enum EventResult {
13pub enum EventResult {
22 Ignored(Option<Callback>),
14 Ignored(Option<Callback>),
helix-term/src/ui/mod.rs+3−2
@@ -32,7 +32,7 @@ pub fn regex_prompt(
32 history_register: Option<char>,
32 history_register: Option<char>,
33 completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
33 completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
34 fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static,
34 fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static,
35−) -> Prompt {
35+) {
36 let (view, doc) = current!(cx.editor);
36 let (view, doc) = current!(cx.editor);
37 let doc_id = view.doc;
37 let doc_id = view.doc;
38 let snapshot = doc.selection(view.id).clone();
38 let snapshot = doc.selection(view.id).clone();
@@ -95,7 +95,8 @@ pub fn regex_prompt(
95 );
95 );
96 // Calculate initial completion
96 // Calculate initial completion
97 prompt.recalculate_completion(cx.editor);
97 prompt.recalculate_completion(cx.editor);
98+ // prompt
98− prompt
99+ cx.push_layer(Box::new(prompt));
99}
100}
100
101
101pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> {
102pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> {