on master help sign in
Factor out append_changes_to_history
commit518426b9f48369f72a49ccdecb23977fac178983 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 7 Oct 2020, 18:31 (6 years ago) parenta5be718
1 file changed+17−6
helix-view/src/commands.rs+17−6
helix-view/src/commands.rs+17−6
@@ -251,6 +251,8 @@ pub fn delete_selection(view: &mut View, _count: usize) {
251251 let transaction =
252252 Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None));
253253 transaction.apply(&mut view.state);
254+
255+ append_changes_to_history(view);
254256}
255257
256258pub fn change_selection(view: &mut View, count: usize) {
@@ -268,9 +270,7 @@ pub fn collapse_selection(view: &mut View, _count: usize) {
268270fn enter_insert_mode(view: &mut View) {
269271 view.state.mode = Mode::Insert;
270272
271− // HAXX
272− view.state.changes = Some(ChangeSet::new(view.state.doc()));
273− view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
273+ append_changes_to_history(view);
274274}
275275// inserts at the start of each selection
276276pub fn insert_mode(view: &mut View, _count: usize) {
@@ -367,9 +367,7 @@ pub fn open_below(view: &mut View, _count: usize) {
367367
368368// O inserts a new line before each line with a selection
369369
370−pub fn normal_mode(view: &mut View, _count: usize) {
371− view.state.mode = Mode::Normal;
372−
370+fn append_changes_to_history(view: &mut View) {
373371 if let Some(changes) = view.state.changes.take() {
374372 // Instead of doing this messy merge we could always commit, and based on transaction
375373 // 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) {
382380 view.history.commit_revision(&transaction, &old_state);
383381 }
384382
383+ // TODO: need to start the state with these vals
384+
385+ // HAXX
386+ view.state.changes = Some(ChangeSet::new(view.state.doc()));
387+ view.state.old_state = Some((view.state.doc().clone(), view.state.selection.clone()));
388+}
389+
390+pub fn normal_mode(view: &mut View, _count: usize) {
391+ view.state.mode = Mode::Normal;
392+
393+ append_changes_to_history(view);
394+
385395 // if leaving append mode, move cursor back by 1
386396 if view.state.restore_cursor {
387397 let text = &view.state.doc.slice(..);
@@ -486,5 +496,6 @@ pub fn paste(view: &mut View, _count: usize) {
486496 });
487497
488498 transaction.apply(&mut view.state);
499+ append_changes_to_history(view);
489500 }
490501}