@@ -368,22 +368,26 @@ pub fn open_below(view: &mut View, _count: usize) {
368368// O inserts a new line before each line with a selection
369369
370370fn append_changes_to_history(view: &mut View) {
371− if let Some(changes) = view.state.changes.take() {
372− // Instead of doing this messy merge we could always commit, and based on transaction
373− // annotations either add a new layer or compose into the previous one.
374− let transaction = Transaction::from(changes).with_selection(view.state.selection().clone());
375− let (doc, selection) = view.state.old_state.take().unwrap();
376− let mut old_state = State::new(doc);
377− old_state.selection = selection;
378−
379− // TODO: take transaction by value?
380− view.history.commit_revision(&transaction, &old_state);
371+ if view.state.changes.is_empty() {
372+ return;
381373 }
382374
383− // TODO: need to start the state with these vals
375+ let new_changeset = ChangeSet::new(view.state.doc());
376+ let changes = std::mem::replace(&mut view.state.changes, new_changeset);
377+ // Instead of doing this messy merge we could always commit, and based on transaction
378+ // annotations either add a new layer or compose into the previous one.
379+ let transaction = Transaction::from(changes).with_selection(view.state.selection().clone());
380+
381+ // HAXX: we need to reconstruct the state as it was before the changes..
382+ let (doc, selection) = view.state.old_state.take().unwrap();
383+ let mut old_state = State::new(doc);
384+ old_state.selection = selection;
384385
386+ // TODO: take transaction by value?
387+ view.history.commit_revision(&transaction, &old_state);
388+
389+ // TODO: need to start the state with these vals
385390 // HAXX
386− view.state.changes = Some(ChangeSet::new(view.state.doc()));
387391 view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
388392}
389393