aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorath32021-11-14 15:11:53 +0000
committerGitHub2021-11-14 15:11:53 +0000
commit35c974c9c49f9127da3798c9a8e49795b3c4aadc (patch)
tree13324c42b38afd053eae9c3c8016f8a00b1af377 /helix-core/src
parent0949a0de7fec9e11f8011693f84b1939b0a6a548 (diff)
Implement "Goto last modification" command (#1067)
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/history.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index b53c01fe..bf2624e2 100644
--- a/helix-core/src/history.rs
+++ b/helix-core/src/history.rs
@@ -1,4 +1,4 @@
-use crate::{ChangeSet, Rope, State, Transaction};
+use crate::{Assoc, ChangeSet, Rope, State, Transaction};
use once_cell::sync::Lazy;
use regex::Regex;
use std::num::NonZeroUsize;
@@ -133,6 +133,34 @@ impl History {
Some(&self.revisions[last_child.get()].transaction)
}
+ // Get the position of last change
+ pub fn last_edit_pos(&self) -> Option<usize> {
+ if self.current == 0 {
+ return None;
+ }
+ let current_revision = &self.revisions[self.current];
+ let primary_selection = current_revision
+ .inversion
+ .selection()
+ .expect("inversion always contains a selection")
+ .primary();
+ let (_from, to, _fragment) = current_revision
+ .transaction
+ .changes_iter()
+ // find a change that matches the primary selection
+ .find(|(from, to, _fragment)| {
+ crate::Range::new(*from, *to).overlaps(&primary_selection)
+ })
+ // or use the first change
+ .or_else(|| current_revision.transaction.changes_iter().next())
+ .unwrap();
+ let pos = current_revision
+ .transaction
+ .changes()
+ .map_pos(to, Assoc::After);
+ Some(pos)
+ }
+
fn lowest_common_ancestor(&self, mut a: usize, mut b: usize) -> usize {
use std::collections::HashSet;
let mut a_path_set = HashSet::new();