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.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 450b4736..21b72b5f 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -19,6 +19,16 @@ 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, |