diff options
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 } |