on master help sign in
Send updates to the lsp on undo/redo.
1ffd1e7Blaž Hrastnik
TODO.md+1−1
@@ -17,7 +17,7 @@
17- [x] retain horiz when moving vertically
17- [x] retain horiz when moving vertically
18- [x] deindent
18- [x] deindent
19- [ ] ensure_cursor_in_view always before rendering? or always in app after event process?
19- [ ] ensure_cursor_in_view always before rendering? or always in app after event process?
20−- [ ] update lsp on redo/undo
20+- [x] update lsp on redo/undo
21- [ ] Implement marks (superset of Selection/Range)
21- [ ] Implement marks (superset of Selection/Range)
22- [ ] ctrl-v/ctrl-x on file picker
22- [ ] ctrl-v/ctrl-x on file picker
23- [ ] linewise selection work
23- [ ] linewise selection work
helix-view/src/document.rs+22−34
@@ -160,24 +160,13 @@ impl Document {
160 self.state.selection = selection;
160 self.state.selection = selection;
161 }
161 }
162
162
163− pub fn apply(&mut self, transaction: &Transaction) -> bool {
163+ pub fn _apply(&mut self, transaction: &Transaction) -> bool {
164 let old_doc = self.text().clone();
164 let old_doc = self.text().clone();
165
165
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−
172 let success = transaction.apply(&mut self.state);
166 let success = transaction.apply(&mut self.state);
173
167
174 if !transaction.changes().is_empty() {
168 if !transaction.changes().is_empty() {
175− // Compose this transaction with the previous one
169+ // TODO: self.version += 1;?
176− take_with(&mut self.changes, |changes| {
177− changes.compose(transaction.changes().clone())
178− });
179−
180− // TODO: when composing, replace transaction.selection too
181
170
182 // update tree-sitter syntax tree
171 // update tree-sitter syntax tree
183 if let Some(syntax) = &mut self.syntax {
172 if let Some(syntax) = &mut self.syntax {
@@ -203,21 +192,28 @@ impl Document {
203 success
192 success
204 }
193 }
205
194
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+
206 pub fn undo(&mut self) -> bool {
213 pub fn undo(&mut self) -> bool {
207 if let Some(transaction) = self.history.undo() {
214 if let Some(transaction) = self.history.undo() {
208− let old_doc = self.text().clone();
209 self.version += 1;
215 self.version += 1;
210− let success = transaction.apply(&mut self.state);
216+ let success = self._apply(&transaction);
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
221
217
222 // reset changeset to fix len
218 // reset changeset to fix len
223 self.changes = ChangeSet::new(self.text());
219 self.changes = ChangeSet::new(self.text());
@@ -229,17 +225,9 @@ impl Document {
229
225
230 pub fn redo(&mut self) -> bool {
226 pub fn redo(&mut self) -> bool {
231 if let Some(transaction) = self.history.redo() {
227 if let Some(transaction) = self.history.redo() {
232− let old_doc = self.text().clone();
233 self.version += 1;
228 self.version += 1;
234− let success = transaction.apply(&mut self.state);
235
229
236− // update tree-sitter syntax tree
230+ let success = self._apply(&transaction);
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− }
243
231
244 // reset changeset to fix len
232 // reset changeset to fix len
245 self.changes = ChangeSet::new(self.text());
233 self.changes = ChangeSet::new(self.text());