|
|
@ -857,11 +857,11 @@ impl Document {
|
|
|
|
success
|
|
|
|
success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn undo_redo_impl(&mut self, view: &mut View, undo: bool) -> bool {
|
|
|
|
fn undo_redo_impl(&mut self, view_id: ViewId, undo: bool) -> bool {
|
|
|
|
let mut history = self.history.take();
|
|
|
|
let mut history = self.history.take();
|
|
|
|
let txn = if undo { history.undo() } else { history.redo() };
|
|
|
|
let txn = if undo { history.undo() } else { history.redo() };
|
|
|
|
let success = if let Some(txn) = txn {
|
|
|
|
let success = if let Some(txn) = txn {
|
|
|
|
self.apply_impl(txn, view.id) && view.apply(txn, self)
|
|
|
|
self.apply_impl(txn, view_id)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
false
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -875,13 +875,13 @@ impl Document {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
|
|
|
|
/// Undo the last modification to the [`Document`]. Returns whether the undo was successful.
|
|
|
|
pub fn undo(&mut self, view: &mut View) -> bool {
|
|
|
|
pub fn undo(&mut self, view_id: ViewId) -> bool {
|
|
|
|
self.undo_redo_impl(view, true)
|
|
|
|
self.undo_redo_impl(view_id, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
|
|
|
|
/// Redo the last modification to the [`Document`]. Returns whether the redo was successful.
|
|
|
|
pub fn redo(&mut self, view: &mut View) -> bool {
|
|
|
|
pub fn redo(&mut self, view_id: ViewId) -> bool {
|
|
|
|
self.undo_redo_impl(view, false)
|
|
|
|
self.undo_redo_impl(view_id, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn savepoint(&mut self) {
|
|
|
|
pub fn savepoint(&mut self) {
|
|
|
@ -894,7 +894,7 @@ impl Document {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn earlier_later_impl(&mut self, view: &mut View, uk: UndoKind, earlier: bool) -> bool {
|
|
|
|
fn earlier_later_impl(&mut self, view_id: ViewId, uk: UndoKind, earlier: bool) -> bool {
|
|
|
|
let txns = if earlier {
|
|
|
|
let txns = if earlier {
|
|
|
|
self.history.get_mut().earlier(uk)
|
|
|
|
self.history.get_mut().earlier(uk)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -902,7 +902,7 @@ impl Document {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let mut success = false;
|
|
|
|
let mut success = false;
|
|
|
|
for txn in txns {
|
|
|
|
for txn in txns {
|
|
|
|
if self.apply_impl(&txn, view.id) && view.apply(&txn, self) {
|
|
|
|
if self.apply_impl(&txn, view_id) {
|
|
|
|
success = true;
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -914,13 +914,13 @@ impl Document {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Undo modifications to the [`Document`] according to `uk`.
|
|
|
|
/// Undo modifications to the [`Document`] according to `uk`.
|
|
|
|
pub fn earlier(&mut self, view: &mut View, uk: UndoKind) -> bool {
|
|
|
|
pub fn earlier(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
|
|
|
|
self.earlier_later_impl(view, uk, true)
|
|
|
|
self.earlier_later_impl(view_id, uk, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Redo modifications to the [`Document`] according to `uk`.
|
|
|
|
/// Redo modifications to the [`Document`] according to `uk`.
|
|
|
|
pub fn later(&mut self, view: &mut View, uk: UndoKind) -> bool {
|
|
|
|
pub fn later(&mut self, view_id: ViewId, uk: UndoKind) -> bool {
|
|
|
|
self.earlier_later_impl(view, uk, false)
|
|
|
|
self.earlier_later_impl(view_id, uk, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Commit pending changes to history
|
|
|
|
/// Commit pending changes to history
|
|
|
|