diff options
author | Blaž Hrastnik | 2021-03-31 06:45:18 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-31 06:45:18 +0000 |
commit | 9eaef6e33376407931162780cd402297c44f26c4 (patch) | |
tree | da14993d99a50f502113befcd0f78538f4e7c716 /helix-view/src | |
parent | dfc17becd56efbc1f65de7c8d65cb32ad4690db1 (diff) |
Fully drop State references.
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 94684362..cf160cca 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -21,6 +21,7 @@ pub struct Document { // rope + selection pub(crate) id: DocumentId, state: State, + path: Option<PathBuf>, /// Current editing mode. @@ -185,9 +186,16 @@ impl Document { fn _apply(&mut self, transaction: &Transaction) -> bool { let old_doc = self.text().clone(); - let success = transaction.apply(&mut self.state); + let success = transaction.changes().apply(&mut self.state.doc); if !transaction.changes().is_empty() { + // update the selection: either take the selection specified in the transaction, or map the + // current selection through changes. + self.state.selection = transaction + .selection() + .cloned() + .unwrap_or_else(|| self.selection().clone().map(transaction.changes())); + self.version += 1; // update tree-sitter syntax tree @@ -415,7 +423,7 @@ mod test { // delete - let transaction = transaction.invert(&old_doc); + let transaction = transaction.invert(&old_doc.doc); let old_doc = doc.state.clone(); doc.apply(&transaction); let changes = Client::changeset_to_changes(&old_doc.doc, doc.text(), transaction.changes()); |