aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-07-30 14:40:58 +0000
committerBlaž Hrastnik2021-07-31 15:44:14 +0000
commit557c63033c57cb60917dd75ac45d14ca11d0557e (patch)
treec4b98a8c6ba4a0c959aa6e95204c24c80dd4e004
parentccecda4f666a8a1167bdb6a0b2f3ef9c331a59f4 (diff)
fix: Map all selections on transaction.apply
-rw-r--r--helix-view/src/document.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index c02d6656..4ad08ce9 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -678,17 +678,21 @@ impl Document {
let success = transaction.changes().apply(&mut self.text);
if success {
- // update the selection: either take the selection specified in the transaction, or map the
- // current selection through changes.
- let selection = transaction
- .selection()
- .cloned()
- .unwrap_or_else(|| self.selection(view_id).clone().map(transaction.changes()));
- self.selections.insert(view_id, selection);
-
- // Ensure all selections accross all views still adhere to invariants.
for selection in self.selections.values_mut() {
- *selection = selection.clone().ensure_invariants(self.text.slice(..));
+ *selection = selection
+ .clone()
+ // Map through changes
+ .map(transaction.changes())
+ // Ensure all selections accross all views still adhere to invariants.
+ .ensure_invariants(self.text.slice(..));
+ }
+
+ // if specified, the current selection should instead be replaced by transaction.selection
+ if let Some(selection) = transaction.selection() {
+ self.selections.insert(
+ view_id,
+ selection.clone().ensure_invariants(self.text.slice(..)),
+ );
}
}