forked from 1b-agent/opencadstudio-upstream
fix(layers): push undo for transparency edits
LayerTransparencyEdit applied without begin/commit_layer_undo, so the edit was permanent while every sibling arm is undoable. Mirrors the color arm inside the non-empty guard. Test: layer_transparency_edit_pushes_undo asserts the entry plus undo-restores (RED first). Full suite: 1991 passed / 0 failed / 25 ignored.
This commit is contained in:
1 parent
1bf584a1c1
commit
4471260c00
2 files changed
+47
-14
No files matched your search
@@ -4656,6 +4656,37 @@ mod layer_name_target_tests {
|
|||||||
.collect();
|
.collect();
|
||||||
assert_eq!(before, after, "unknown name must change nothing");
|
assert_eq!(before, after, "unknown name must change nothing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn layer_transparency_edit_pushes_undo() {
|
||||||
|
// #43: every sibling layer arm pushes an undo entry; transparency must too.
|
||||||
|
let mut app = OpenCADStudio::new_for_test();
|
||||||
|
app.automation_op(r#"{"op":"new"}"#);
|
||||||
|
let i = app.active_tab;
|
||||||
|
app.finish_pending_history(i);
|
||||||
|
let before = app.tabs[i].history.undo_stack.len();
|
||||||
|
let _ = app.update(Message::LayerTransparencyEdit("0".to_string(), "50".to_string()));
|
||||||
|
assert_eq!(
|
||||||
|
app.tabs[i].history.undo_stack.len(),
|
||||||
|
before + 1,
|
||||||
|
"transparency edit must push an undo entry like its siblings"
|
||||||
|
);
|
||||||
|
let panel = app.tabs[i]
|
||||||
|
.layers
|
||||||
|
.layers
|
||||||
|
.iter()
|
||||||
|
.find(|l| l.name == "0")
|
||||||
|
.expect("layer 0 in panel");
|
||||||
|
assert_eq!(panel.transparency, 50);
|
||||||
|
app.undo_active_tab();
|
||||||
|
let panel = app.tabs[i]
|
||||||
|
.layers
|
||||||
|
.layers
|
||||||
|
.iter()
|
||||||
|
.find(|l| l.name == "0")
|
||||||
|
.expect("layer 0 in panel");
|
||||||
|
assert_eq!(panel.transparency, 0, "undo must restore transparency");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
+16
-14
@@ -3717,23 +3717,25 @@ impl OpenCADStudio {
|
|||||||
// Apply the edited transparency to every selected layer (#236).
|
// Apply the edited transparency to every selected layer (#236).
|
||||||
if let Some(v) = val {
|
if let Some(v) = val {
|
||||||
let targets = self.layer_row_action_targets(i, idx);
|
let targets = self.layer_row_action_targets(i, idx);
|
||||||
for name in &targets {
|
|
||||||
if let Some(layer) = self.tabs[i].scene.document.layers.get_mut(name) {
|
|
||||||
layer.transparency =
|
|
||||||
codec::types::Transparency::from_percent(v as f64 / 100.0);
|
|
||||||
}
|
|
||||||
if let Some(pl) = self.tabs[i]
|
|
||||||
.layers
|
|
||||||
.layers
|
|
||||||
.iter_mut()
|
|
||||||
.find(|l| &l.name == name)
|
|
||||||
{
|
|
||||||
pl.transparency = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !targets.is_empty() {
|
if !targets.is_empty() {
|
||||||
|
let undo = self.begin_layer_undo(i, "LAYER TRANSPARENCY", &targets);
|
||||||
|
for name in &targets {
|
||||||
|
if let Some(layer) = self.tabs[i].scene.document.layers.get_mut(name) {
|
||||||
|
layer.transparency =
|
||||||
|
codec::types::Transparency::from_percent(v as f64 / 100.0);
|
||||||
|
}
|
||||||
|
if let Some(pl) = self.tabs[i]
|
||||||
|
.layers
|
||||||
|
.layers
|
||||||
|
.iter_mut()
|
||||||
|
.find(|l| &l.name == name)
|
||||||
|
{
|
||||||
|
pl.transparency = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
self.tabs[i].scene.invalidate_layer_dependencies(&targets);
|
self.tabs[i].scene.invalidate_layer_dependencies(&targets);
|
||||||
self.tabs[i].dirty = true;
|
self.tabs[i].dirty = true;
|
||||||
|
self.commit_layer_undo(i, undo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
|
|||||||
Reference in new issue
Block a user