From 9eaef6e33376407931162780cd402297c44f26c4 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 31 Mar 2021 15:45:18 +0900 Subject: Fully drop State references. --- helix-view/src/document.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'helix-view') 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, /// 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()); -- cgit v1.2.3-70-g09d2