on master help sign in
Simplify old_state handling.
commitefc5aa2016e56e0721d125a20e3573d25af4dd76 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 23 Oct 2020, 11:36 (6 years ago) parentc0e17dd
3 files changed+4−9
helix-core/src/state.rs+1 helix-view/src/commands.rs+1−7 helix-view/src/document.rs+2−2
helix-core/src/state.rs+1
@@ -4,6 +4,7 @@ use crate::{ChangeSet, Diagnostic, Position, Range, Rope, RopeSlice, Selection,
44use anyhow::Error;
55
66/// A state represents the current editor state of a single buffer.
7+#[derive(Clone)]
78pub struct State {
89 // TODO: fields should be private but we need to refactor commands.rs first
910 pub doc: Rope,
helix-view/src/commands.rs+1−7
@@ -411,15 +411,9 @@ fn append_changes_to_history(view: &mut View) {
411411 // TODO: trigger lsp/documentDidChange with changes
412412
413413 // HAXX: we need to reconstruct the state as it was before the changes..
414− let (doc, selection) = view.doc.old_state.take().unwrap();
415− let mut old_state = State::new(doc);
416− old_state.selection = selection;
417−
414+ let old_state = std::mem::replace(&mut view.doc.old_state, view.doc.state.clone());
418415 // TODO: take transaction by value?
419416 view.doc.history.commit_revision(&transaction, &old_state);
420−
421− // HAXX
422− view.doc.old_state = Some((view.doc.text().clone(), view.doc.state.selection.clone()));
423417}
424418
425419pub fn normal_mode(view: &mut View, _count: usize) {
helix-view/src/document.rs+2−2
@@ -27,9 +27,9 @@ pub struct Document {
2727
2828 /// Pending changes since last history commit.
2929 pub changes: ChangeSet,
30+ pub old_state: State,
3031 pub history: History,
3132 pub version: i64, // should be usize?
32− pub old_state: Option<(Rope, Selection)>,
3333
3434 pub diagnostics: Vec<Diagnostic>,
3535}
@@ -55,7 +55,7 @@ use url::Url;
5555impl Document {
5656 fn new(state: State) -> Self {
5757 let changes = ChangeSet::new(&state.doc);
58− let old_state = Some((state.doc.clone(), Selection::single(0, 0)));
58+ let old_state = state.clone();
5959
6060 Self {
6161 path: None,