fix: Map all selections on transaction.apply

pull/538/head
Blaž Hrastnik 3 years ago
parent ccecda4f66
commit 557c63033c

@ -678,17 +678,21 @@ impl Document {
let success = transaction.changes().apply(&mut self.text); let success = transaction.changes().apply(&mut self.text);
if success { 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() { 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(..)),
);
} }
} }

Loading…
Cancel
Save