@@ -160,24 +160,13 @@ impl Document {
160160 self.state.selection = selection;
161161 }
162162
163− pub fn apply(&mut self, transaction: &Transaction) -> bool {
163+ pub fn _apply(&mut self, transaction: &Transaction) -> bool {
164164 let old_doc = self.text().clone();
165165
166− // store the state just before any changes are made. This allows us to undo to the
167− // state just before a transaction was applied.
168− if self.changes.is_empty() && !transaction.changes().is_empty() {
169− self.old_state = Some(self.state.clone());
170− }
171−
172166 let success = transaction.apply(&mut self.state);
173167
174168 if !transaction.changes().is_empty() {
175− // Compose this transaction with the previous one
176− take_with(&mut self.changes, |changes| {
177− changes.compose(transaction.changes().clone())
178− });
179−
180− // TODO: when composing, replace transaction.selection too
169+ // TODO: self.version += 1;?
181170
182171 // update tree-sitter syntax tree
183172 if let Some(syntax) = &mut self.syntax {
@@ -203,21 +192,28 @@ impl Document {
203192 success
204193 }
205194
195+ pub fn apply(&mut self, transaction: &Transaction) -> bool {
196+ // store the state just before any changes are made. This allows us to undo to the
197+ // state just before a transaction was applied.
198+ if self.changes.is_empty() && !transaction.changes().is_empty() {
199+ self.old_state = Some(self.state.clone());
200+ }
201+
202+ let success = self._apply(&transaction);
203+
204+ if !transaction.changes().is_empty() {
205+ // Compose this transaction with the previous one
206+ take_with(&mut self.changes, |changes| {
207+ changes.compose(transaction.changes().clone())
208+ });
209+ }
210+ success
211+ }
212+
206213 pub fn undo(&mut self) -> bool {
207214 if let Some(transaction) = self.history.undo() {
208− let old_doc = self.text().clone();
209215 self.version += 1;
210− let success = transaction.apply(&mut self.state);
211−
212− // update tree-sitter syntax tree
213− if let Some(syntax) = &mut self.syntax {
214− // TODO: no unwrap
215− syntax
216− .update(&old_doc, &self.state.doc, transaction.changes())
217− .unwrap();
218− }
219−
220− // TODO: undo / redo need to emit changes to lsp
216+ let success = self._apply(&transaction);
221217
222218 // reset changeset to fix len
223219 self.changes = ChangeSet::new(self.text());
@@ -229,17 +225,9 @@ impl Document {
229225
230226 pub fn redo(&mut self) -> bool {
231227 if let Some(transaction) = self.history.redo() {
232− let old_doc = self.text().clone();
233228 self.version += 1;
234− let success = transaction.apply(&mut self.state);
235229
236− // update tree-sitter syntax tree
237− if let Some(syntax) = &mut self.syntax {
238− // TODO: no unwrap
239− syntax
240− .update(&old_doc, &self.state.doc, transaction.changes())
241− .unwrap();
242− }
230+ let success = self._apply(&transaction);
243231
244232 // reset changeset to fix len
245233 self.changes = ChangeSet::new(self.text());