mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-30 05:37:00 -06:00
Engine: a rolled-back group takes back only the steps recorded in its workbook
A rollback took back every step recorded since its group began, so an edit recorded in another workbook while the group was open was lost from the recording although the edit stayed. It now takes back only the steps recorded in the group's own workbook. - Test: the other workbook's edit in `stop_action_runs_only_on_its_own_and_is_not_recorded`.
This commit is contained in:
@@ -879,7 +879,7 @@ impl Session {
|
||||
// The steps recorded while the group was open go with their edits (all of them when the
|
||||
// recording started inside the group).
|
||||
if let Some(rec) = self.recorder.as_mut() {
|
||||
rec.cut_back(g.recorded.unwrap_or((0, 0)));
|
||||
rec.cut_back(g.recorded.unwrap_or((0, 0)), g.doc);
|
||||
}
|
||||
// The record of the last group step stays when the document is back exactly where that
|
||||
// step left it (this group began there); otherwise the rollback is where the group ended.
|
||||
|
||||
@@ -73,13 +73,18 @@ impl Recorder {
|
||||
(self.steps.len(), self.dropped)
|
||||
}
|
||||
|
||||
/// Takes back the steps recorded since `mark` (an undo group that recorded them was rolled
|
||||
/// back, so playing them back would make edits the workbook no longer has).
|
||||
pub(crate) fn cut_back(&mut self, (len, dropped): (usize, usize)) {
|
||||
if self.steps.len() > len {
|
||||
self.steps.truncate(len);
|
||||
/// Takes back the steps recorded in the document with uid `doc` since `mark` (an undo group
|
||||
/// on it was rolled back, so playing them back would make edits it no longer has). Steps in
|
||||
/// other documents stay: their edits do too. Steps the buffer dropped stay counted.
|
||||
pub(crate) fn cut_back(&mut self, (len, _): (usize, usize), doc: u64) {
|
||||
let before = self.steps.len();
|
||||
let mut i = 0;
|
||||
self.steps.retain(|s| {
|
||||
i += 1;
|
||||
i <= len || s.doc != doc
|
||||
});
|
||||
if self.steps.len() != before {
|
||||
self.bytes = self.steps.iter().map(|s| serde_json::to_vec(s).map_or(0, |v| v.len())).sum();
|
||||
}
|
||||
self.dropped = self.dropped.min(dropped);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -844,6 +844,16 @@ fn stop_action_runs_only_on_its_own_and_is_not_recorded() {
|
||||
assert_eq!(s.execute("automate.stopAction", json!({})).unwrap(), json!({"stopped": true}));
|
||||
assert!(v(&s, "A3").is_empty());
|
||||
assert_eq!(recorded_ids(&s), ["cell.set", "cell.set"]);
|
||||
// An edit recorded in another workbook while the group was open stays, as its edit does.
|
||||
let first = s.active_index();
|
||||
let _left = s.group_begin("Left open").unwrap();
|
||||
set(&mut s, "A4", "four");
|
||||
s.new_workbook();
|
||||
set(&mut s, "B1", "other");
|
||||
s.set_active(first);
|
||||
assert_eq!(s.execute("automate.stopAction", json!({})).unwrap(), json!({"stopped": true}));
|
||||
assert_eq!(recorded_ids(&s), ["cell.set", "cell.set", "cell.set"], "the other workbook's edit stays");
|
||||
assert_eq!(s.recorder.as_ref().unwrap().steps.last().map(|st| st.params["cell"].clone()), Some(json!("B1")));
|
||||
assert_eq!(s.stop_recording().unwrap().dropped, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user