on master help sign in
fix: Map all selections on transaction.apply
commit557c63033c57cb60917dd75ac45d14ca11d0557e authorBlaž Hrastnik <blaz@mxxn.io> dateFri 30 Jul 2021, 23:40 (5 years ago) parentccecda4
1 file changed+14−10
helix-view/src/document.rs+14−10
helix-view/src/document.rs+14−10
@@ -678,17 +678,21 @@ impl Document {
678678 let success = transaction.changes().apply(&mut self.text);
679679
680680 if success {
681− // update the selection: either take the selection specified in the transaction, or map the
682− // current selection through changes.
683− let selection = transaction
684− .selection()
685− .cloned()
686− .unwrap_or_else(|| self.selection(view_id).clone().map(transaction.changes()));
687− self.selections.insert(view_id, selection);
688−
689− // Ensure all selections accross all views still adhere to invariants.
690681 for selection in self.selections.values_mut() {
691− *selection = selection.clone().ensure_invariants(self.text.slice(..));
682+ *selection = selection
683+ .clone()
684+ // Map through changes
685+ .map(transaction.changes())
686+ // Ensure all selections accross all views still adhere to invariants.
687+ .ensure_invariants(self.text.slice(..));
688+ }
689+
690+ // if specified, the current selection should instead be replaced by transaction.selection
691+ if let Some(selection) = transaction.selection() {
692+ self.selections.insert(
693+ view_id,
694+ selection.clone().ensure_invariants(self.text.slice(..)),
695+ );
692696 }
693697 }
694698