on master help sign in
Simplify old_state handling.
efc5aa2Blaž Hrastnik
helix-core/src/state.rs+1
@@ -4,6 +4,7 @@ use crate::{ChangeSet, Diagnostic, Position, Range, Rope, RopeSlice, Selection,
4use anyhow::Error;
4use anyhow::Error;
5
5
6/// A state represents the current editor state of a single buffer.
6/// A state represents the current editor state of a single buffer.
7+#[derive(Clone)]
7pub struct State {
8pub struct State {
8 // TODO: fields should be private but we need to refactor commands.rs first
9 // TODO: fields should be private but we need to refactor commands.rs first
9 pub doc: Rope,
10 pub doc: Rope,
helix-view/src/commands.rs+1−7
@@ -411,15 +411,9 @@ fn append_changes_to_history(view: &mut View) {
411 // TODO: trigger lsp/documentDidChange with changes
411 // TODO: trigger lsp/documentDidChange with changes
412
412
413 // HAXX: we need to reconstruct the state as it was before the changes..
413 // HAXX: we need to reconstruct the state as it was before the changes..
414− let (doc, selection) = view.doc.old_state.take().unwrap();
414+ let old_state = std::mem::replace(&mut view.doc.old_state, view.doc.state.clone());
415− let mut old_state = State::new(doc);
416− old_state.selection = selection;
417−
418 // TODO: take transaction by value?
415 // TODO: take transaction by value?
419 view.doc.history.commit_revision(&transaction, &old_state);
416 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()));
423}
417}
424
418
425pub fn normal_mode(view: &mut View, _count: usize) {
419pub fn normal_mode(view: &mut View, _count: usize) {
helix-view/src/document.rs+2−2
@@ -27,9 +27,9 @@ pub struct Document {
27
27
28 /// Pending changes since last history commit.
28 /// Pending changes since last history commit.
29 pub changes: ChangeSet,
29 pub changes: ChangeSet,
30+ pub old_state: State,
30 pub history: History,
31 pub history: History,
31 pub version: i64, // should be usize?
32 pub version: i64, // should be usize?
32− pub old_state: Option<(Rope, Selection)>,
33
33
34 pub diagnostics: Vec<Diagnostic>,
34 pub diagnostics: Vec<Diagnostic>,
35}
35}
@@ -55,7 +55,7 @@ use url::Url;
55impl Document {
55impl Document {
56 fn new(state: State) -> Self {
56 fn new(state: State) -> Self {
57 let changes = ChangeSet::new(&state.doc);
57 let changes = ChangeSet::new(&state.doc);
58− let old_state = Some((state.doc.clone(), Selection::single(0, 0)));
58+ let old_state = state.clone();
59
59
60 Self {
60 Self {
61 path: None,
61 path: None,