Make regex_prompt directly call cx.push_layer

pull/1872/head
Blaž Hrastnik 3 years ago
parent 83b3272166
commit 5c162ef995
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640

@ -1411,7 +1411,7 @@ fn select_all(cx: &mut Context) {
fn select_regex(cx: &mut Context) { fn select_regex(cx: &mut Context) {
let reg = cx.register.unwrap_or('/'); let reg = cx.register.unwrap_or('/');
let prompt = ui::regex_prompt( ui::regex_prompt(
cx, cx,
"select:".into(), "select:".into(),
Some(reg), Some(reg),
@ -1428,13 +1428,11 @@ fn select_regex(cx: &mut Context) {
} }
}, },
); );
cx.push_layer(Box::new(prompt));
} }
fn split_selection(cx: &mut Context) { fn split_selection(cx: &mut Context) {
let reg = cx.register.unwrap_or('/'); let reg = cx.register.unwrap_or('/');
let prompt = ui::regex_prompt( ui::regex_prompt(
cx, cx,
"split:".into(), "split:".into(),
Some(reg), Some(reg),
@ -1448,8 +1446,6 @@ fn split_selection(cx: &mut Context) {
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
}, },
); );
cx.push_layer(Box::new(prompt));
} }
fn split_selection_on_newline(cx: &mut Context) { 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 contents = doc.text().slice(..).to_string();
let completions = search_completions(cx, Some(reg)); let completions = search_completions(cx, Some(reg));
let prompt = ui::regex_prompt( ui::regex_prompt(
cx, cx,
"search:".into(), "search:".into(),
Some(reg), 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) { 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 file_picker_config = config.file_picker.clone();
let completions = search_completions(cx, None); let completions = search_completions(cx, None);
let prompt = ui::regex_prompt( ui::regex_prompt(
cx, cx,
"global-search:".into(), "global-search:".into(),
None, 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 current_path = doc_mut!(cx.editor).path().cloned();
let show_picker = async move { 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) { fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
// keep or remove selections matching regex // keep or remove selections matching regex
let reg = cx.register.unwrap_or('/'); let reg = cx.register.unwrap_or('/');
let prompt = ui::regex_prompt( ui::regex_prompt(
cx, cx,
if remove { "remove:" } else { "keep:" }.into(), if remove { "remove:" } else { "keep:" }.into(),
Some(reg), Some(reg),
@ -3417,9 +3409,7 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
}, },
); )
cx.push_layer(Box::new(prompt));
} }
fn keep_selections(cx: &mut Context) { fn keep_selections(cx: &mut Context) {

@ -9,14 +9,6 @@ use tui::buffer::Buffer as Surface;
pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>; 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 // Cursive-inspired
pub enum EventResult { pub enum EventResult {
Ignored(Option<Callback>), Ignored(Option<Callback>),

@ -32,7 +32,7 @@ pub fn regex_prompt(
history_register: Option<char>, history_register: Option<char>,
completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static, completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static, fun: impl Fn(&mut View, &mut Document, Regex, PromptEvent) + 'static,
) -> Prompt { ) {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
let doc_id = view.doc; let doc_id = view.doc;
let snapshot = doc.selection(view.id).clone(); let snapshot = doc.selection(view.id).clone();
@ -95,7 +95,8 @@ pub fn regex_prompt(
); );
// Calculate initial completion // Calculate initial completion
prompt.recalculate_completion(cx.editor); 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> { pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> {

Loading…
Cancel
Save