@@ -251,6 +251,8 @@ pub fn delete_selection(view: &mut View, _count: usize) {
251 let transaction =
251 let transaction =
252 Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None));
252 Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None));
253 transaction.apply(&mut view.state);
253 transaction.apply(&mut view.state);
255+ append_changes_to_history(view);
256pub fn change_selection(view: &mut View, count: usize) {
258pub fn change_selection(view: &mut View, count: usize) {
@@ -268,9 +270,7 @@ pub fn collapse_selection(view: &mut View, _count: usize) {
268fn enter_insert_mode(view: &mut View) {
270fn enter_insert_mode(view: &mut View) {
269 view.state.mode = Mode::Insert;
271 view.state.mode = Mode::Insert;
271− // HAXX
273+ append_changes_to_history(view);
272− view.state.changes = Some(ChangeSet::new(view.state.doc()));
273− view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
275// inserts at the start of each selection
275// inserts at the start of each selection
276pub fn insert_mode(view: &mut View, _count: usize) {
276pub fn insert_mode(view: &mut View, _count: usize) {
@@ -367,9 +367,7 @@ pub fn open_below(view: &mut View, _count: usize) {
368// O inserts a new line before each line with a selection
368// O inserts a new line before each line with a selection
370−pub fn normal_mode(view: &mut View, _count: usize) {
370+fn append_changes_to_history(view: &mut View) {
371− view.state.mode = Mode::Normal;
373 if let Some(changes) = view.state.changes.take() {
371 if let Some(changes) = view.state.changes.take() {
374 // Instead of doing this messy merge we could always commit, and based on transaction
372 // Instead of doing this messy merge we could always commit, and based on transaction
375 // annotations either add a new layer or compose into the previous one.
373 // annotations either add a new layer or compose into the previous one.
@@ -382,6 +380,18 @@ pub fn normal_mode(view: &mut View, _count: usize) {
382 view.history.commit_revision(&transaction, &old_state);
380 view.history.commit_revision(&transaction, &old_state);
383+ // TODO: need to start the state with these vals
386+ view.state.changes = Some(ChangeSet::new(view.state.doc()));
387+ view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
390+pub fn normal_mode(view: &mut View, _count: usize) {
391+ view.state.mode = Mode::Normal;
393+ append_changes_to_history(view);
385 // if leaving append mode, move cursor back by 1
395 // if leaving append mode, move cursor back by 1
386 if view.state.restore_cursor {
396 if view.state.restore_cursor {
387 let text = &view.state.doc.slice(..);
397 let text = &view.state.doc.slice(..);
@@ -486,5 +496,6 @@ pub fn paste(view: &mut View, _count: usize) {
488 transaction.apply(&mut view.state);
498 transaction.apply(&mut view.state);
499+ append_changes_to_history(view);