@@ -22,7 +22,7 @@ pub enum Mode {
2222pub struct Document {
2323 // rope + selection
2424 pub(crate) id: DocumentId,
25− state: State,
25+ text: Rope,
2626 pub(crate) selections: HashMap<ViewId, Selection>,
2727
2828 path: Option<PathBuf>,
@@ -75,7 +75,7 @@ impl Document {
7575 Self {
7676 id: DocumentId::default(),
7777 path: None,
78− state: State::new(text),
78+ text,
7979 selections: HashMap::default(),
8080 mode: Mode::Normal,
8181 restore_cursor: false,
@@ -160,7 +160,7 @@ impl Document {
160160 ) {
161161 if let Some(language_config) = language_config {
162162 if let Some(highlight_config) = language_config.highlight_config(scopes) {
163− let syntax = Syntax::new(&self.state.doc, highlight_config);
163+ let syntax = Syntax::new(&self.text, highlight_config);
164164 self.syntax = Some(syntax);
165165 // TODO: config.configure(scopes) is now delayed, is that ok?
166166 }
@@ -190,7 +190,7 @@ impl Document {
190190 fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
191191 let old_doc = self.text().clone();
192192
193− let success = transaction.changes().apply(&mut self.state.doc);
193+ let success = transaction.changes().apply(&mut self.text);
194194
195195 if !transaction.changes().is_empty() {
196196 // update the selection: either take the selection specified in the transaction, or map the
@@ -207,7 +207,7 @@ impl Document {
207207 if let Some(syntax) = &mut self.syntax {
208208 // TODO: no unwrap
209209 syntax
210− .update(&old_doc, &self.state.doc, transaction.changes())
210+ .update(&old_doc, &self.text, transaction.changes())
211211 .unwrap();
212212 }
213213
@@ -236,7 +236,10 @@ impl Document {
236236 // store the state just before any changes are made. This allows us to undo to the
237237 // state just before a transaction was applied.
238238 if self.changes.is_empty() && !transaction.changes().is_empty() {
239− self.old_state = Some(self.state.clone());
239+ self.old_state = Some(State {
240+ doc: self.text.clone(),
241+ selection: self.selection(view_id).clone(),
242+ });
240243 }
241244
242245 let success = self._apply(&transaction, view_id);
@@ -365,7 +368,7 @@ impl Document {
365368 }
366369
367370 pub fn text(&self) -> &Rope {
368− &self.state.doc
371+ &self.text
369372 }
370373
371374 pub fn selection(&self, view_id: ViewId) -> &Selection {
@@ -412,9 +415,9 @@ mod test {
412415 // insert
413416
414417 let transaction = Transaction::insert(doc.text(), doc.selection(view), " world".into());
415− let old_doc = doc.state.clone();
418+ let old_doc = doc.text().clone();
416419 doc.apply(&transaction, view);
417− let changes = Client::changeset_to_changes(&old_doc.doc, doc.text(), transaction.changes());
420+ let changes = Client::changeset_to_changes(&old_doc, doc.text(), transaction.changes());
418421
419422 assert_eq!(
420423 changes,
@@ -430,10 +433,10 @@ mod test {
430433
431434 // delete
432435
433− let transaction = transaction.invert(&old_doc.doc);
434− let old_doc = doc.state.clone();
436+ let transaction = transaction.invert(&old_doc);
437+ let old_doc = doc.text().clone();
435438 doc.apply(&transaction, view);
436− let changes = Client::changeset_to_changes(&old_doc.doc, doc.text(), transaction.changes());
439+ let changes = Client::changeset_to_changes(&old_doc, doc.text(), transaction.changes());
437440
438441 // line: 0-based.
439442 // col: 0-based, gaps between chars.
@@ -459,13 +462,13 @@ mod test {
459462
460463 doc.set_selection(view, Selection::single(0, 5));
461464 let transaction = Transaction::change(
462− &doc.state.doc,
465+ doc.text(),
463466 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
464467 );
465468 // aeilou
469+ let old_doc = doc.text().clone();
466470 doc.apply(&transaction, view);
467− let changes =
468− Client::changeset_to_changes(&doc.state.doc, doc.text(), transaction.changes());
471+ let changes = Client::changeset_to_changes(&old_doc, doc.text(), transaction.changes());
469472
470473 assert_eq!(
471474 changes,