From f8cace7957224913e32271ad42cfaef1a1410701 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:17:57 +0000 Subject: [PATCH] docs: add comments describing algorithm for replacing character --- helix-term/src/commands.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1c0011c60..de8efeea9 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5657,7 +5657,6 @@ fn surround_add_impl( fn surround_add(cx: &mut Context) { cx.on_next_key(move |cx, event| { let (view, doc) = current!(cx.editor); - // surround_len is the number of new characters being added. match event.char() { Some(ch) => { if ch == 'x' { @@ -5705,7 +5704,7 @@ fn surround_add(cx: &mut Context) { } fn surround_replace(cx: &mut Context) { - let count = cx.count(); + let layer = cx.count(); cx.on_next_key(move |cx, event| { let surround_ch = match event.char() { Some('m') => None, // m selects the closest surround pair @@ -5716,8 +5715,11 @@ fn surround_replace(cx: &mut Context) { let text = doc.text().slice(..); let selection = doc.selection(view.id); + // the first character represents the index of the first change + // the second character represents the index of the second change let change_pos = - match surround::get_surround_pos(doc.syntax(), text, selection, surround_ch, count) { + // also interested in changing this + match surround::get_surround_pos(doc.syntax(), text, selection, surround_ch, layer) { Ok(c) => c, Err(err) => { cx.editor.set_error(err.to_string()); @@ -5738,6 +5740,7 @@ fn surround_replace(cx: &mut Context) { Some(to) => to, None => return doc.set_selection(view.id, selection), }; + // we are interested in changing this specifically let (open, close) = match_brackets::get_pair(to); // the changeset has to be sorted to allow nested surrounds @@ -5753,6 +5756,7 @@ fn surround_replace(cx: &mut Context) { sorted_pos.iter().map(|&pos| { let mut t = Tendril::new(); t.push(pos.1); + log::error!("{:?}, {:?}", pos.0, Some(&t)); (pos.0, pos.0 + 1, Some(t)) }), );