diff options
author | Blaž Hrastnik | 2020-09-28 16:01:27 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-09-28 16:01:27 +0000 |
commit | 36e7e2133fe1d472600cfd935b8046b8d50146c2 (patch) | |
tree | 887eb91b778bce0ec4a07d3a3c41cb53376579fb /helix-core/src/transaction.rs | |
parent | 3020077da8efbf914a9cb0a2cbb50362d339a39a (diff) |
Split selection on regex, fix InputEdit generation.
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r-- | helix-core/src/transaction.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 278e071b..a8059497 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -326,9 +326,20 @@ impl Transaction { /// Returns true if applied successfully. pub fn apply(&self, state: &mut State) -> bool { - // apply changes to the document - if !self.changes.apply(&mut state.doc) { - return false; + if !self.changes.is_empty() { + // TODO: also avoid mapping the selection if not necessary + + let old_doc = state.doc().clone(); + + // apply changes to the document + if !self.changes.apply(&mut state.doc) { + return false; + } + + if let Some(syntax) = &mut state.syntax { + // TODO: no unwrap + syntax.update(&old_doc, &state.doc, &self.changes).unwrap(); + } } // update the selection: either take the selection specified in the transaction, or map the @@ -338,14 +349,6 @@ impl Transaction { .clone() .unwrap_or_else(|| state.selection.clone().map(&self.changes)); - // TODO: no unwrap - state - .syntax - .as_mut() - .unwrap() - .update(&state.doc, &self.changes) - .unwrap(); - true } |