aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/document.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-28 22:57:00 +0000
committerNathan Vegdahl2021-07-28 22:57:00 +0000
commitcd7302ffd35c4972e7b0414a31a08f4e3c672df5 (patch)
treef4e8cbcacd3c6b54d2261eae457ec41be54fc2ce /helix-view/src/document.rs
parenta873e719d5dd1816434c16bb02d74f1e00ca847a (diff)
Enforce cursor/selection invariants in one place.
Rather than per-command like before.
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r--helix-view/src/document.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 84de4c43..c2078060 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -792,7 +792,8 @@ impl Document {
pub fn set_selection(&mut self, view_id: ViewId, selection: Selection) {
// TODO: use a transaction?
- self.selections.insert(view_id, selection);
+ self.selections
+ .insert(view_id, selection.ensure_invariants(self.text().slice(..)));
}
fn apply_impl(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
@@ -807,7 +808,12 @@ impl Document {
.selection()
.cloned()
.unwrap_or_else(|| self.selection(view_id).clone().map(transaction.changes()));
- self.set_selection(view_id, selection);
+ 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(..));
+ }
}
if !transaction.changes().is_empty() {