From dba438832c52616fe2cec88188c3b78c309d4142 Mon Sep 17 00:00:00 2001 From: Sam Vente Date: Sun, 9 Jun 2024 19:54:08 +0200 Subject: [PATCH] add some comments to register_mark --- helix-term/src/commands/typed.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 1df89749e..34980505f 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -461,9 +461,12 @@ fn register_mark( |s| s.as_ref().chars().next(), ) .unwrap_or('^'); + let (view, doc) = current!(cx.editor); - let ranges = doc.selection(view.id).ranges(); - let ranges_str = ranges + + let ranges_str = doc + .selection(view.id) + .ranges() .iter() .map(|r| r.to_string()) .collect::>(); @@ -472,6 +475,11 @@ fn register_mark( let history = doc.history.take(); let current_history_point = history.current_revision(); doc.history.replace(history); + + // doc_id so we know which doc to switch to + // current_history_point so we can apply changes + // to our selection when we restore it. + // the rest of the elements are just the stringified ranges let mut register_val = vec![ format!("{}", doc.id()), format!("{}", current_history_point), @@ -530,12 +538,6 @@ fn parse_mark_register_contents( } } -fn get_revisions_to_apply(doc: &mut Document, history_rev: usize) -> Option { - let history = doc.history.take(); - let revisions_to_apply = history.changes_since(history_rev); - doc.history.replace(history); - revisions_to_apply -} fn goto_mark( cx: &mut compositor::Context, args: &[Cow], @@ -557,7 +559,9 @@ fn goto_mark( cx.editor.switch(doc_id, Action::Replace); let (view, doc) = current!(cx.editor); - let revisions_to_apply = get_revisions_to_apply(doc, history_rev); + let history = doc.history.take(); + let revisions_to_apply = history.changes_since(history_rev); + doc.history.replace(history); selection = match revisions_to_apply { Some(t) => selection.map(t.changes()),