mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
fix: Map all selections on transaction.apply
This commit is contained in:
parent
ccecda4f66
commit
557c63033c
@ -678,17 +678,21 @@ fn apply_impl(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
|
||||
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(..)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user