@@ -22,7 +22,7 @@ pub enum Mode {
22pub struct Document {
22pub struct Document {
23 // rope + selection
23 // rope + selection
24 pub(crate) id: DocumentId,
24 pub(crate) id: DocumentId,
25− state: State,
25+ text: Rope,
26 pub(crate) selections: HashMap<ViewId, Selection>,
26 pub(crate) selections: HashMap<ViewId, Selection>,
28 path: Option<PathBuf>,
28 path: Option<PathBuf>,
@@ -75,7 +75,7 @@ impl Document {
76 id: DocumentId::default(),
76 id: DocumentId::default(),
77 path: None,
77 path: None,
78− state: State::new(text),
78+ text,
79 selections: HashMap::default(),
79 selections: HashMap::default(),
80 mode: Mode::Normal,
80 mode: Mode::Normal,
81 restore_cursor: false,
81 restore_cursor: false,
@@ -160,7 +160,7 @@ impl Document {
161 if let Some(language_config) = language_config {
161 if let Some(language_config) = language_config {
162 if let Some(highlight_config) = language_config.highlight_config(scopes) {
162 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);
164 self.syntax = Some(syntax);
164 self.syntax = Some(syntax);
165 // TODO: config.configure(scopes) is now delayed, is that ok?
165 // TODO: config.configure(scopes) is now delayed, is that ok?
@@ -190,7 +190,7 @@ impl Document {
190 fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
190 fn _apply(&mut self, transaction: &Transaction, view_id: ViewId) -> bool {
191 let old_doc = self.text().clone();
191 let old_doc = self.text().clone();
193− let success = transaction.changes().apply(&mut self.state.doc);
193+ let success = transaction.changes().apply(&mut self.text);
195 if !transaction.changes().is_empty() {
195 if !transaction.changes().is_empty() {
196 // update the selection: either take the selection specified in the transaction, or map the
196 // update the selection: either take the selection specified in the transaction, or map the
@@ -207,7 +207,7 @@ impl Document {
207 if let Some(syntax) = &mut self.syntax {
207 if let Some(syntax) = &mut self.syntax {
208 // TODO: no unwrap
208 // TODO: no unwrap
210− .update(&old_doc, &self.state.doc, transaction.changes())
210+ .update(&old_doc, &self.text, transaction.changes())
211 .unwrap();
211 .unwrap();
@@ -236,7 +236,10 @@ impl Document {
236 // store the state just before any changes are made. This allows us to undo to the
236 // store the state just before any changes are made. This allows us to undo to the
237 // state just before a transaction was applied.
237 // state just before a transaction was applied.
238 if self.changes.is_empty() && !transaction.changes().is_empty() {
238 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 let success = self._apply(&transaction, view_id);
245 let success = self._apply(&transaction, view_id);
@@ -365,7 +368,7 @@ impl Document {
367 pub fn text(&self) -> &Rope {
370 pub fn text(&self) -> &Rope {
368− &self.state.doc
371+ &self.text
371 pub fn selection(&self, view_id: ViewId) -> &Selection {
374 pub fn selection(&self, view_id: ViewId) -> &Selection {
@@ -412,9 +415,9 @@ mod test {
412 // insert
415 // insert
414 let transaction = Transaction::insert(doc.text(), doc.selection(view), " world".into());
417 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();
416 doc.apply(&transaction, view);
419 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());
419 assert_eq!(
422 assert_eq!(
@@ -430,10 +433,10 @@ mod test {
431 // delete
434 // delete
433− let transaction = transaction.invert(&old_doc.doc);
436+ let transaction = transaction.invert(&old_doc);
434− let old_doc = doc.state.clone();
437+ let old_doc = doc.text().clone();
435 doc.apply(&transaction, view);
438 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());
438 // line: 0-based.
441 // line: 0-based.
439 // col: 0-based, gaps between chars.
442 // col: 0-based, gaps between chars.
@@ -459,13 +462,13 @@ mod test {
460 doc.set_selection(view, Selection::single(0, 5));
463 doc.set_selection(view, Selection::single(0, 5));
461 let transaction = Transaction::change(
464 let transaction = Transaction::change(
462− &doc.state.doc,
465+ doc.text(),
463 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
466 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
465 // aeilou
468 // aeilou
469+ let old_doc = doc.text().clone();
466 doc.apply(&transaction, view);
470 doc.apply(&transaction, view);
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());
470 assert_eq!(
473 assert_eq!(