Simplify old_state handling.

pull/5/head
Blaž Hrastnik 4 years ago
parent c0e17dd324
commit efc5aa2016

@ -4,6 +4,7 @@ use crate::{ChangeSet, Diagnostic, Position, Range, Rope, RopeSlice, Selection,
use anyhow::Error; use anyhow::Error;
/// A state represents the current editor state of a single buffer. /// A state represents the current editor state of a single buffer.
#[derive(Clone)]
pub struct State { pub struct State {
// TODO: fields should be private but we need to refactor commands.rs first // TODO: fields should be private but we need to refactor commands.rs first
pub doc: Rope, pub doc: Rope,

@ -411,15 +411,9 @@ fn append_changes_to_history(view: &mut View) {
// TODO: trigger lsp/documentDidChange with changes // TODO: trigger lsp/documentDidChange with changes
// HAXX: we need to reconstruct the state as it was before the changes.. // HAXX: we need to reconstruct the state as it was before the changes..
let (doc, selection) = view.doc.old_state.take().unwrap(); let old_state = std::mem::replace(&mut view.doc.old_state, view.doc.state.clone());
let mut old_state = State::new(doc);
old_state.selection = selection;
// TODO: take transaction by value? // TODO: take transaction by value?
view.doc.history.commit_revision(&transaction, &old_state); view.doc.history.commit_revision(&transaction, &old_state);
// HAXX
view.doc.old_state = Some((view.doc.text().clone(), view.doc.state.selection.clone()));
} }
pub fn normal_mode(view: &mut View, _count: usize) { pub fn normal_mode(view: &mut View, _count: usize) {

@ -27,9 +27,9 @@ pub struct Document {
/// Pending changes since last history commit. /// Pending changes since last history commit.
pub changes: ChangeSet, pub changes: ChangeSet,
pub old_state: State,
pub history: History, pub history: History,
pub version: i64, // should be usize? pub version: i64, // should be usize?
pub old_state: Option<(Rope, Selection)>,
pub diagnostics: Vec<Diagnostic>, pub diagnostics: Vec<Diagnostic>,
} }
@ -55,7 +55,7 @@ use url::Url;
impl Document { impl Document {
fn new(state: State) -> Self { fn new(state: State) -> Self {
let changes = ChangeSet::new(&state.doc); let changes = ChangeSet::new(&state.doc);
let old_state = Some((state.doc.clone(), Selection::single(0, 0))); let old_state = state.clone();
Self { Self {
path: None, path: None,

Loading…
Cancel
Save