forked from 1b-agent/opencadstudio-upstream
feat(block-editor): isolate session history and add save checkpoints
This commit is contained in:
1 parent
535710e5d1
commit
f39fb31137
15 files changed
+1002
-255
No files matched your search
+34
-3
@@ -152,7 +152,7 @@ impl OpenCADStudio {
|
||||
defer_history_drop(discarded);
|
||||
}
|
||||
|
||||
fn push_undo_entry(&mut self, i: usize, snapshot: HistorySnapshot) {
|
||||
pub(super) fn push_undo_entry(&mut self, i: usize, snapshot: HistorySnapshot) {
|
||||
self.tabs[i].history.undo_stack.push(snapshot);
|
||||
self.tabs[i].edit_revision = self.tabs[i].edit_revision.wrapping_add(1);
|
||||
self.clear_redo_history(i);
|
||||
@@ -283,6 +283,7 @@ impl OpenCADStudio {
|
||||
return;
|
||||
};
|
||||
self.tabs[i].scene.document.end_entity_change_recording();
|
||||
self.reconcile_block_edit_membership(i);
|
||||
let structure_after = self.tabs[i].scene.document.snapshot_structure();
|
||||
let before_images = pending.recorder.take_before_images();
|
||||
let added_handles: Vec<Handle> = before_images
|
||||
@@ -292,11 +293,25 @@ impl OpenCADStudio {
|
||||
.then_some(*handle)
|
||||
})
|
||||
.collect();
|
||||
let block_members = self.tabs[i]
|
||||
.active_block_edit_session()
|
||||
.and_then(|session| {
|
||||
pending
|
||||
.structure_before
|
||||
.block_records
|
||||
.get(&session.block_name)
|
||||
.map(|record| (session.block_name.clone(), record.entity_handles.clone()))
|
||||
});
|
||||
codec::CadDocument::align_added_entity_structure(
|
||||
&mut pending.structure_before,
|
||||
&structure_after,
|
||||
&added_handles,
|
||||
);
|
||||
if let Some((name, members)) = block_members {
|
||||
if let Some(record) = pending.structure_before.block_records.get_mut(&name) {
|
||||
record.entity_handles = members;
|
||||
}
|
||||
}
|
||||
let structure_changed = pending.structure_before != structure_after;
|
||||
let entities: Vec<_> = before_images
|
||||
.into_iter()
|
||||
@@ -402,8 +417,8 @@ impl OpenCADStudio {
|
||||
) -> Option<PendingDelta> {
|
||||
self.finish_pending_history(i);
|
||||
let label = label.into();
|
||||
let structure_before =
|
||||
(!delta_safe).then(|| self.tabs[i].scene.document.snapshot_structure());
|
||||
let structure_before = (!delta_safe || self.tabs[i].active_block_edit.is_some())
|
||||
.then(|| self.tabs[i].scene.document.snapshot_structure());
|
||||
self.tabs[i].scene.begin_undo_recording();
|
||||
Some(PendingDelta {
|
||||
label,
|
||||
@@ -740,6 +755,7 @@ impl OpenCADStudio {
|
||||
let Some(rec) = self.tabs[i].scene.take_undo_recording() else {
|
||||
return;
|
||||
};
|
||||
self.reconcile_block_edit_membership(i);
|
||||
// The predicate should have kept the command entity-only; if a primitive
|
||||
// still poisoned the recording we've already mutated and the pre-command
|
||||
// full state is gone, so the entity delta is the best we can do (its
|
||||
@@ -813,6 +829,16 @@ impl OpenCADStudio {
|
||||
let mut structure = pending.structure_before.map(StructureSnapshot::Full);
|
||||
if let Some(before_structure) = structure.as_mut() {
|
||||
if let StructureSnapshot::Full(before_structure) = before_structure {
|
||||
let block_members = self.tabs[i]
|
||||
.active_block_edit_session()
|
||||
.and_then(|session| {
|
||||
before_structure
|
||||
.block_records
|
||||
.get(&session.block_name)
|
||||
.map(|record| {
|
||||
(session.block_name.clone(), record.entity_handles.clone())
|
||||
})
|
||||
});
|
||||
let after_structure = self.tabs[i].scene.document.snapshot_structure();
|
||||
let added_handles: Vec<Handle> = entities
|
||||
.iter()
|
||||
@@ -825,6 +851,11 @@ impl OpenCADStudio {
|
||||
&after_structure,
|
||||
&added_handles,
|
||||
);
|
||||
if let Some((name, members)) = block_members {
|
||||
if let Some(record) = before_structure.block_records.get_mut(&name) {
|
||||
record.entity_handles = members;
|
||||
}
|
||||
}
|
||||
if *before_structure == after_structure {
|
||||
structure = None;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user