Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r--helix-core/src/transaction.rs41
1 files changed, 7 insertions, 34 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 37be2e2e..f24f2094 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -19,16 +19,6 @@ pub enum Operation {
Insert(Tendril),
}
-impl Operation {
- /// The number of characters affected by the operation.
- pub fn len_chars(&self) -> usize {
- match self {
- Self::Retain(n) | Self::Delete(n) => *n,
- Self::Insert(s) => s.chars().count(),
- }
- }
-}
-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Assoc {
Before,
@@ -39,12 +29,6 @@ pub enum Assoc {
/// Acts like `Before` if a word character is inserted
/// before the position, otherwise acts like `After`
BeforeWord,
- /// Acts like `Before` but if the position is within an exact replacement
- /// (exact size) the offset to the start of the replacement is kept
- BeforeSticky,
- /// Acts like `After` but if the position is within an exact replacement
- /// (exact size) the offset to the start of the replacement is kept
- AfterSticky,
}
impl Assoc {
@@ -56,17 +40,13 @@ impl Assoc {
fn insert_offset(self, s: &str) -> usize {
let chars = s.chars().count();
match self {
- Assoc::After | Assoc::AfterSticky => chars,
+ Assoc::After => chars,
Assoc::AfterWord => s.chars().take_while(|&c| char_is_word(c)).count(),
// return position before inserted text
- Assoc::Before | Assoc::BeforeSticky => 0,
+ Assoc::Before => 0,
Assoc::BeforeWord => chars - s.chars().rev().take_while(|&c| char_is_word(c)).count(),
}
}
-
- pub fn sticky(self) -> bool {
- matches!(self, Assoc::BeforeSticky | Assoc::AfterSticky)
- }
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
@@ -361,7 +341,6 @@ impl ChangeSet {
pos += s.chars().count();
}
}
- println!("=>\n{text}");
}
true
}
@@ -477,14 +456,8 @@ impl ChangeSet {
if pos == old_pos && assoc.stay_at_gaps() {
new_pos
} else {
- let ins = assoc.insert_offset(s);
- // if the deleted and inserted text have the exact same size
- // keep the relative offset into the new text
- if *len == ins && assoc.sticky() {
- new_pos + (pos - old_pos)
- } else {
- new_pos + assoc.insert_offset(s)
- }
+ // place to end of insert
+ new_pos + assoc.insert_offset(s)
}
}),
i
@@ -521,7 +494,7 @@ impl ChangeSet {
pos
}
- pub fn changes_iter(&self) -> ChangeIterator<'_> {
+ pub fn changes_iter(&self) -> ChangeIterator {
ChangeIterator::new(self)
}
}
@@ -754,7 +727,7 @@ impl Transaction {
})
}
- pub fn changes_iter(&self) -> ChangeIterator<'_> {
+ pub fn changes_iter(&self) -> ChangeIterator {
self.changes.changes_iter()
}
}
@@ -780,7 +753,7 @@ impl<'a> ChangeIterator<'a> {
}
}
-impl Iterator for ChangeIterator<'_> {
+impl<'a> Iterator for ChangeIterator<'a> {
type Item = Change;
fn next(&mut self) -> Option<Self::Item> {