refactor: make surround_add use surround_add_impl in all of its brancehs

pull/12055/head
Nikita Revenco 3 weeks ago
parent d739761636
commit b126d9aeef

@ -5678,10 +5678,10 @@ fn surround_add(cx: &mut Context) {
cx.on_next_key(move |cx, event| { cx.on_next_key(move |cx, event| {
let (view, doc) = current!(cx.editor); let (view, doc) = current!(cx.editor);
// surround_len is the number of new characters being added. // surround_len is the number of new characters being added.
let (open, close, surround_len) = match event.char() { match event.char() {
Some(ch) => { Some(ch) => {
let mut open = Tendril::new(); // let mut open = Tendril::new();
let mut close = Tendril::new(); // let mut close = Tendril::new();
// let length = if ch == 'x' { // let length = if ch == 'x' {
// let prompt = create_surround_prompt(cx.editor, "none".into(), Some('z')); // let prompt = create_surround_prompt(cx.editor, "none".into(), Some('z'));
// cx.push_layer(prompt); // cx.push_layer(prompt);
@ -5692,25 +5692,30 @@ fn surround_add(cx: &mut Context) {
// // Any character other than "x" will cause 2 chars to get added // // Any character other than "x" will cause 2 chars to get added
// 2 // 2
// } else { // } else {
let (o, c) = match_brackets::get_pair(ch); let (open, close) = match_brackets::get_pair(ch);
open.push(o); // open.push(o);
close.push(c); // close.push(c);
// Any character other than "x" will cause 2 chars to get added // Any character other than "x" will cause 2 chars to get added
// 2 // 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) // (open, close, 2)
}
None if event.code == KeyCode::Enter => {
let open = doc.line_ending.as_str().into();
let close = doc.line_ending.as_str().into();
let length = 2 * doc.line_ending.len_chars();
surround_add_impl(doc, view, length, open, close);
exit_select_mode(cx);
} }
None if event.code == KeyCode::Enter => (
doc.line_ending.as_str().into(),
doc.line_ending.as_str().into(),
2 * doc.line_ending.len_chars(),
),
None => return, None => return,
}; };
surround_add_impl(doc, view, surround_len, open, close);
exit_select_mode(cx);
// let selection = doc.selection(view.id); // let selection = doc.selection(view.id);
// let mut changes = Vec::with_capacity(selection.len() * 2); // let mut changes = Vec::with_capacity(selection.len() * 2);
// let mut ranges = SmallVec::with_capacity(selection.len()); // let mut ranges = SmallVec::with_capacity(selection.len());

Loading…
Cancel
Save