From 089c2028fa06f5b1820ed7f4cfcc34f50492db8c Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:51:39 +0000 Subject: [PATCH] refactor: remove unnecessary abstraction (create_surround_prompt) --- helix-term/src/commands.rs | 77 +++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1ec2a2d21..5153e3404 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5626,26 +5626,26 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { cx.editor.autoinfo = Some(Info::new(title, &help_text)); } -fn create_surround_prompt( - editor: &Editor, - prefill: String, - history_register: Option, -) -> Box { - let prompt = Prompt::new( - "tag name:".into(), - // TODO: change this to actually be history_register - Some('z'), - ui::completers::none, - move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {}, - ) - .with_line("temp".into(), editor); - - Box::new(prompt) -} +// fn create_surround_prompt( +// editor: &Editor, +// prefill: String, +// history_register: Option, +// callback_fn: impl FnMut(&mut compositor::Context<'_>, &str, PromptEvent) + 'static, +// ) -> Box { +// let prompt = Prompt::new( +// "tag name:".into(), +// // TODO: change this to actually be history_register +// Some('z'), +// ui::completers::none, +// callback_fn, +// ) +// .with_line("temp".into(), editor); + +// Box::new(prompt) +// } fn surround_add_impl( doc: &mut Document, - // cx: &mut Context<'_>, view: &mut View, surround_len: usize, open: Tendril, @@ -5671,7 +5671,6 @@ fn surround_add_impl( let transaction = Transaction::change(doc.text(), changes.into_iter()) .with_selection(Selection::new(ranges, selection.primary_index())); doc.apply(&transaction, view.id); - // exit_select_mode(cx); } fn surround_add(cx: &mut Context) { @@ -5680,31 +5679,23 @@ fn surround_add(cx: &mut Context) { // surround_len is the number of new characters being added. match event.char() { Some(ch) => { - // let mut open = Tendril::new(); - // let mut close = Tendril::new(); - // let length = if ch == 'x' { - // let prompt = create_surround_prompt(cx.editor, "none".into(), Some('z')); - // cx.push_layer(prompt); - - // let (o, c) = match_brackets::get_pair(ch); - // open.push(o); - // close.push(c); - // // Any character other than "x" will cause 2 chars to get added - // 2 - // } else { - let (open, close) = match_brackets::get_pair(ch); - // open.push(o); - // close.push(c); - // Any character other than "x" will cause 2 chars to get added - // 2 - // - let open = Tendril::from(open.to_string()); - let close = Tendril::from(close.to_string()); - - surround_add_impl(doc, view, 2, open, close); - exit_select_mode(cx); - // }; - // (open, close, 2) + if ch == 'x' { + let prompt = Prompt::new( + "tag name:".into(), + Some('z'), + ui::completers::none, + move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {}, + ) + .with_line("temp".into(), cx.editor); + cx.push_layer(prompt); + } else { + let (open, close) = match_brackets::get_pair(ch); + let open = Tendril::from(open.to_string()); + let close = Tendril::from(close.to_string()); + + surround_add_impl(doc, view, 2, open, close); + exit_select_mode(cx); + }; } None if event.code == KeyCode::Enter => { let open = doc.line_ending.as_str().into();