From 36e7e2133fe1d472600cfd935b8046b8d50146c2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 29 Sep 2020 01:01:27 +0900 Subject: Split selection on regex, fix InputEdit generation. --- helix-core/src/transaction.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'helix-core/src/transaction.rs') 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 } -- cgit v1.2.3-70-g09d2