use canvist_model::Commit;
use canvist_model::Document;
use crate::Binding;
use crate::CollabError;
use crate::Track;
pub trait History {
type Error;
fn record(
&mut self,
doc: &mut Document,
commit: &Commit,
merge: bool,
) -> Result<Commit, Self::Error>;
fn undo(&mut self, doc: &mut Document) -> Result<Option<Commit>, Self::Error>;
fn redo(&mut self, doc: &mut Document) -> Result<Option<Commit>, Self::Error>;
fn can_undo(&self) -> bool;
fn can_redo(&self) -> bool;
}
impl History for Binding {
type Error = CollabError;
fn record(
&mut self,
doc: &mut Document,
commit: &Commit,
merge: bool,
) -> Result<Commit, Self::Error> {
let track = if merge { Track::Merge } else { Track::Step };
self.apply_local(doc, commit, track)
}
fn undo(&mut self, doc: &mut Document) -> Result<Option<Commit>, Self::Error> {
Binding::undo(self, doc)
}
fn redo(&mut self, doc: &mut Document) -> Result<Option<Commit>, Self::Error> {
Binding::redo(self, doc)
}
fn can_undo(&self) -> bool {
Binding::can_undo(self)
}
fn can_redo(&self) -> bool {
Binding::can_redo(self)
}
}