From 786226706950d4f346259cf9d9094dcbf9ffc7ef Mon Sep 17 00:00:00 2001 From: MikeeI Date: Mon, 5 Oct 2026 07:37:12 +0200 Subject: [PATCH] fix(engine): preserve redo on unchanged bit depth (#133) --- crates/engine/src/image_cmds.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/image_cmds.rs b/crates/engine/src/image_cmds.rs index 9c1075c7ea4..ee865a6d898 100644 --- a/crates/engine/src/image_cmds.rs +++ b/crates/engine/src/image_cmds.rs @@ -314,10 +314,12 @@ fn convert_mode(s: &mut Session, mode: ColorMode, p: &Value) -> Result { /// Image → Mode → 8/16/32 Bits/Channel. fn convert_depth(s: &mut Session, depth: SampleType) -> Result { + let current = s.active().ok_or(EngineError::NoDocument)?.doc.depth; + if current == depth { + // History::record clears redo even when an edit closure leaves the document unchanged. + return Ok(Value::Null); + } s.edit("Bit Depth", |doc, _| { - if doc.depth == depth { - return Ok(()); - } for_each_surface(&mut doc.layers, true, &mut |surf, _| { let f = surf.format().with_sample(depth); *surf = surf.convert(f); @@ -550,6 +552,11 @@ mod tests { assert_eq!((d.mode, d.depth), (ColorMode::Rgb, SampleType::U8)); s.execute("edit.undo", json!({})).unwrap(); assert_eq!(doc(&s).depth, SampleType::F32); + let revision = s.active().unwrap().revision; + s.execute("image.mode.bits32", json!({})).unwrap(); + assert_eq!(s.active().unwrap().revision, revision, "an unchanged bit depth must preserve the history branch"); + assert!(s.redo(), "selecting the current depth must not discard the undone conversion"); + assert_eq!(doc(&s).depth, SampleType::U8); } #[test]