@@ -678,17 +678,21 @@ impl Document {
678 let success = transaction.changes().apply(&mut self.text);
678 let success = transaction.changes().apply(&mut self.text);
680 if success {
680 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
686− .unwrap_or_else(|| self.selection(view_id).clone().map(transaction.changes()));
687− self.selections.insert(view_id, selection);
689− // Ensure all selections accross all views still adhere to invariants.
690 for selection in self.selections.values_mut() {
681 for selection in self.selections.values_mut() {
682+ *selection = selection
684+ // Map through changes
685+ .map(transaction.changes())
686+ // Ensure all selections accross all views still adhere to invariants.
691− *selection = selection.clone().ensure_invariants(self.text.slice(..));
687+ .ensure_invariants(self.text.slice(..));
690+ // if specified, the current selection should instead be replaced by transaction.selection
691+ if let Some(selection) = transaction.selection() {
692+ self.selections.insert(
694+ selection.clone().ensure_invariants(self.text.slice(..)),