From 2eef428d407a6954bd692466508dca9de622f498 Mon Sep 17 00:00:00 2001 From: Sebastian Berschneider Date: Fri, 16 Oct 2026 08:31:57 +0200 Subject: [PATCH 01/57] Import: preserve embedded rating, flag and label from file metadata --- crates/engine/src/files.rs | 19 +++++++++++++++++++ crates/engine/src/import.rs | 9 +++++++++ crates/engine/src/media.rs | 4 ++++ crates/engine/src/sidecar.rs | 13 +++++-------- crates/engine/src/tests_import.rs | 20 ++++++++++++++++++++ 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index dd246cf848..88e96c416c 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -137,6 +137,13 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { let content_hash = Some(lightcraft_preview::hash_bytes(bytes).to_string()); let m = lightcraft_meta::extract(bytes); let (meta, captured) = meta_of(&m); + let (rating, flag) = match m.rating { + Some(r) if r < 0 => (0, lightcraft_catalog::Flag::Reject), + Some(r) => (r.clamp(0, 5) as u8, lightcraft_catalog::Flag::None), + None => (0, lightcraft_catalog::Flag::None), + }; + let label = m.label.as_deref().and_then(|l| lightcraft_catalog::ColorLabel::parse(l.trim())); + let label_text = m.label.clone(); if lightcraft_raw::probe(bytes).is_some() { let raw = match lightcraft_raw::probe_info(bytes).map_err(|e| preview_reason(bytes, e)) { Ok(r) => r, @@ -151,6 +158,10 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { file_size: bytes.len() as u64, captured, meta, + rating, + flag, + label, + label_text, as_shot_wb: None, content_hash, xmp: lightcraft_meta::embedded(bytes).xmp, @@ -178,6 +189,10 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { captured, file_modified: None, meta, + rating, + flag, + label, + label_text, as_shot_wb, content_hash, xmp: lightcraft_meta::embedded(bytes).xmp, @@ -210,6 +225,10 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { captured, file_modified: None, meta, + rating, + flag, + label, + label_text, as_shot_wb: None, content_hash, embedded_lens: None, diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rs index 9aa847b01f..8cecda6f56 100644 --- a/crates/engine/src/import.rs +++ b/crates/engine/src/import.rs @@ -1091,6 +1091,12 @@ impl ImportJob { let mut q = Photo::new(PhotoId(0), Source::File { path: path.clone() }, &own, &info.format, 0, 0, &self.now); q.captured = info.captured.clone(); q.meta = info.meta.clone(); + q.rating = info.rating; + q.flag = info.flag; + q.label = info.label; + if let Some(sc) = &sidecar { + crate::sidecar::merge_into(&mut q, sc, &self.now); + } let name = opts.rename.as_deref().filter(|t| !t.trim().is_empty()).map(|t| { let n = crate::rename::expand(t, &q, self.seq); self.seq += 1; @@ -1415,6 +1421,9 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepare p.file_size = info.file_size; p.captured = info.captured; p.meta = info.meta; + p.rating = info.rating; + p.flag = info.flag; + p.label = info.label_text.as_deref().and_then(|t| s.catalog.label_from_name(t)).or(info.label); p.as_shot_wb = info.as_shot_wb; p.content_hash = info.content_hash; p.embedded_lens = info.embedded_lens; diff --git a/crates/engine/src/media.rs b/crates/engine/src/media.rs index 22d76528d6..681b0bd5ce 100644 --- a/crates/engine/src/media.rs +++ b/crates/engine/src/media.rs @@ -1658,6 +1658,10 @@ pub struct ProbeInfo { /// metadata would otherwise all land under "Unknown Date"). pub file_modified: Option, pub meta: lightcraft_catalog::Meta, + pub rating: u8, + pub flag: lightcraft_catalog::Flag, + pub label: Option, + pub label_text: Option, pub as_shot_wb: Option<(f64, f64)>, /// Hash of the file's bytes (hex), for duplicate detection. When it is a 32-digit /// [`lightcraft_preview::hash_bytes`] of the whole file (as the native probe computes it), diff --git a/crates/engine/src/sidecar.rs b/crates/engine/src/sidecar.rs index ea06d69a75..f3c47edc07 100644 --- a/crates/engine/src/sidecar.rs +++ b/crates/engine/src/sidecar.rs @@ -498,19 +498,16 @@ fn file_path(p: &Photo) -> Option<&str> { } } -/// The XMP packet that describes a photo on disk: its sidecar, else (raw/DNG) the embedded XMP. -pub fn read_packet(original: &str, kind: MediaKind, naming: SidecarNaming) -> Option<(String, PathBuf)> { +/// The XMP packet that describes a photo on disk: its sidecar, else the file's embedded XMP. +pub fn read_packet(original: &str, _kind: MediaKind, naming: SidecarNaming) -> Option<(String, PathBuf)> { if let Some(sc) = find_sidecar(original, naming) && let Ok(s) = std::fs::read_to_string(&sc) { return Some((s, sc)); } - if kind == MediaKind::Raw { - let bytes = std::fs::read(original).ok()?; - let x = lightcraft_meta::embedded(&bytes).xmp?; - return Some((x, PathBuf::from(original))); - } - None + let bytes = std::fs::read(original).ok()?; + let x = lightcraft_meta::embedded(&bytes).xmp?; + Some((x, PathBuf::from(original))) } /// Photo ids touched by an op (for auto-write). diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index 3d6469deb0..25e7bae42d 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -1748,3 +1748,23 @@ fn presets_apply_the_imported_profile_they_name() { assert_eq!(apply(&mut s, "Portra Soft").profile.id, "lc.vivid"); let _ = std::fs::remove_dir_all(&src); } + +#[test] +fn import_preserves_embedded_rating_and_label() { + use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; + let src = temp_dir("embedded-rating-test"); + let px = [128u8; 40 * 30 * 3]; + let xmp = r#""#; + let meta = EncodeMeta { xmp: Some(xmp), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("photo.jpg"), &bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.join("photo.jpg").to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 1); + let p = s.catalog.photos().next().unwrap(); + assert_eq!(p.rating, 5); + assert_eq!(p.label, Some(lightcraft_catalog::ColorLabel::Blue)); + + let _ = std::fs::remove_dir_all(&src); +} From ffede6c9f78ae4697f6135b4634df9f74a04ec0e Mon Sep 17 00:00:00 2001 From: Sebastian Berschneider Date: Mon, 19 Oct 2026 15:02:55 +0200 Subject: [PATCH 02/57] Import: preserve embedded ratings, flags and labels via existing XMP sidecar pipeline - Apply embedded XMP to JPEG/TIFF during import via parse_sidecar and merge_into - Keep kind == Raw guard in sidecar::read_packet so non-raw originals are not read whole - Handle EXIF Rating tag (0x4746) including rejected (-1) rating in metadata extraction and writing - Add tests for embedded XMP rating & label, EXIF rating, and rejected (-1) ratings --- crates/engine/src/files.rs | 39 +++++++++------------ crates/engine/src/import.rs | 11 ++---- crates/engine/src/media.rs | 4 --- crates/engine/src/sidecar.rs | 13 ++++--- crates/engine/src/tests_import.rs | 57 +++++++++++++++++++++++++++++-- crates/meta/src/exif.rs | 13 ++++++- 6 files changed, 95 insertions(+), 42 deletions(-) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index c7fc994eee..81d41d0a09 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -125,6 +125,19 @@ pub fn embedded_lens(raw: &lightcraft_raw::RawInfo) -> Option Option { + match lightcraft_meta::embedded(bytes).xmp { + Some(x) if !x.contains("Rating") && m.rating.is_some() => { + let fresh = lightcraft_meta::write_xmp(m, None); + lightcraft_meta::merge_xmp(&x, &fresh, lightcraft_meta::MergeRules { owned_if_present: &["xmp:Rating"], ..Default::default() }) + .ok() + .or(Some(x)) + } + Some(x) => Some(x), + None => m.rating.map(|_| lightcraft_meta::write_xmp(m, None)), + } +} + fn ext_upper(name: &str) -> String { std::path::Path::new(name).extension().map(|e| e.to_string_lossy().to_uppercase()).unwrap_or_default() } @@ -137,13 +150,7 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { let content_hash = Some(lightcraft_preview::hash_bytes(bytes).to_string()); let m = lightcraft_meta::extract(bytes); let (meta, captured) = meta_of(&m); - let (rating, flag) = match m.rating { - Some(r) if r < 0 => (0, lightcraft_catalog::Flag::Reject), - Some(r) => (r.clamp(0, 5) as u8, lightcraft_catalog::Flag::None), - None => (0, lightcraft_catalog::Flag::None), - }; - let label = m.label.as_deref().and_then(|l| lightcraft_catalog::ColorLabel::parse(l.trim())); - let label_text = m.label.clone(); + let xmp = embedded_or_exif_xmp(bytes, &m); if lightcraft_raw::probe(bytes).is_some() { let raw = match lightcraft_raw::probe_info(bytes).map_err(|e| preview_reason(bytes, e)) { Ok(r) => r, @@ -158,13 +165,9 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { file_size: bytes.len() as u64, captured, meta, - rating, - flag, - label, - label_text, as_shot_wb: None, content_hash, - xmp: lightcraft_meta::embedded(bytes).xmp, + xmp, preview_only: Some(why), ..Default::default() }); @@ -189,13 +192,9 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { captured, file_modified: None, meta, - rating, - flag, - label, - label_text, as_shot_wb, content_hash, - xmp: lightcraft_meta::embedded(bytes).xmp, + xmp, preview_only: None, }); } @@ -225,14 +224,10 @@ pub fn probe_bytes(name: &str, bytes: &[u8]) -> Result { captured, file_modified: None, meta, - rating, - flag, - label, - label_text, as_shot_wb: None, content_hash, embedded_lens: None, - xmp: None, + xmp, preview_only: None, }) } diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rs index 8cecda6f56..2b5d7aeda0 100644 --- a/crates/engine/src/import.rs +++ b/crates/engine/src/import.rs @@ -1060,12 +1060,13 @@ impl ImportJob { plan.slots.push(Slot::Item(PreparedItem::Duplicate { path, existing: *existing, reason: "content", hash: Some(h.clone()) })); continue; } - // the XMP sidecar (or a raw's embedded XMP), read before copying: its capture time files + // the XMP sidecar (or a file's embedded XMP), read before copying: its capture time files // and names the copy when the file itself has none let raw = info.kind == MediaKind::Raw; + let has_embedded_xmp = raw || matches!(info.format.as_str(), "JPEG" | "JPG" | "TIFF" | "TIF"); let packet = crate::sidecar::find_sidecar(&path, self.naming) .and_then(|f| std::fs::read_to_string(f).ok()) - .or_else(|| info.xmp.clone().filter(|_| raw)); + .or_else(|| info.xmp.clone().filter(|_| has_embedded_xmp)); let target = crate::crs::Target::for_file(info.kind, &info.format, info.preview_only.is_some(), &info.meta.camera); let sidecar = packet.and_then(|x| match crate::sidecar::parse_sidecar(&x, target) { Ok(sc) => Some(sc), @@ -1091,9 +1092,6 @@ impl ImportJob { let mut q = Photo::new(PhotoId(0), Source::File { path: path.clone() }, &own, &info.format, 0, 0, &self.now); q.captured = info.captured.clone(); q.meta = info.meta.clone(); - q.rating = info.rating; - q.flag = info.flag; - q.label = info.label; if let Some(sc) = &sidecar { crate::sidecar::merge_into(&mut q, sc, &self.now); } @@ -1421,9 +1419,6 @@ pub fn commit_prepared(s: &mut Session, opts: &ImportOptions, now: &str, prepare p.file_size = info.file_size; p.captured = info.captured; p.meta = info.meta; - p.rating = info.rating; - p.flag = info.flag; - p.label = info.label_text.as_deref().and_then(|t| s.catalog.label_from_name(t)).or(info.label); p.as_shot_wb = info.as_shot_wb; p.content_hash = info.content_hash; p.embedded_lens = info.embedded_lens; diff --git a/crates/engine/src/media.rs b/crates/engine/src/media.rs index 681b0bd5ce..22d76528d6 100644 --- a/crates/engine/src/media.rs +++ b/crates/engine/src/media.rs @@ -1658,10 +1658,6 @@ pub struct ProbeInfo { /// metadata would otherwise all land under "Unknown Date"). pub file_modified: Option, pub meta: lightcraft_catalog::Meta, - pub rating: u8, - pub flag: lightcraft_catalog::Flag, - pub label: Option, - pub label_text: Option, pub as_shot_wb: Option<(f64, f64)>, /// Hash of the file's bytes (hex), for duplicate detection. When it is a 32-digit /// [`lightcraft_preview::hash_bytes`] of the whole file (as the native probe computes it), diff --git a/crates/engine/src/sidecar.rs b/crates/engine/src/sidecar.rs index 5ffa6b5042..cdee1e8942 100644 --- a/crates/engine/src/sidecar.rs +++ b/crates/engine/src/sidecar.rs @@ -500,16 +500,19 @@ fn file_path(p: &Photo) -> Option<&str> { } } -/// The XMP packet that describes a photo on disk: its sidecar, else the file's embedded XMP. -pub fn read_packet(original: &str, _kind: MediaKind, naming: SidecarNaming) -> Option<(String, PathBuf)> { +/// The XMP packet that describes a photo on disk: its sidecar, else (raw/DNG) the embedded XMP. +pub fn read_packet(original: &str, kind: MediaKind, naming: SidecarNaming) -> Option<(String, PathBuf)> { if let Some(sc) = find_sidecar(original, naming) && let Ok(s) = std::fs::read_to_string(&sc) { return Some((s, sc)); } - let bytes = std::fs::read(original).ok()?; - let x = lightcraft_meta::embedded(&bytes).xmp?; - Some((x, PathBuf::from(original))) + if kind == MediaKind::Raw { + let bytes = std::fs::read(original).ok()?; + let x = lightcraft_meta::embedded(&bytes).xmp?; + return Some((x, PathBuf::from(original))); + } + None } /// Photo ids touched by an op (for auto-write). diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index e9f3365f41..2ac89d4661 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -1794,9 +1794,9 @@ fn presets_apply_the_imported_profile_they_name() { } #[test] -fn import_preserves_embedded_rating_and_label() { +fn import_preserves_embedded_xmp_rating_and_label() { use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; - let src = temp_dir("embedded-rating-test"); + let src = temp_dir("embedded-xmp-rating-test"); let px = [128u8; 40 * 30 * 3]; let xmp = r#""#; let meta = EncodeMeta { xmp: Some(xmp), ..Default::default() }; @@ -1808,7 +1808,60 @@ fn import_preserves_embedded_rating_and_label() { assert_eq!(ids(&r, "imported"), 1); let p = s.catalog.photos().next().unwrap(); assert_eq!(p.rating, 5); + assert_eq!(p.flag, lightcraft_catalog::Flag::None); assert_eq!(p.label, Some(lightcraft_catalog::ColorLabel::Blue)); let _ = std::fs::remove_dir_all(&src); } + +#[test] +fn import_preserves_embedded_exif_rating() { + use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; + let src = temp_dir("embedded-exif-rating-test"); + let px = [128u8; 40 * 30 * 3]; + let exif = lightcraft_meta::write_exif(&lightcraft_meta::Metadata { rating: Some(3), ..Default::default() }); + let meta = EncodeMeta { exif: Some(&exif), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("exif_rating.jpg"), &bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.join("exif_rating.jpg").to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 1); + let p = s.catalog.photos().next().unwrap(); + assert_eq!(p.rating, 3); + assert_eq!(p.flag, lightcraft_catalog::Flag::None); + + let _ = std::fs::remove_dir_all(&src); +} + +#[test] +fn import_preserves_embedded_rejected_rating() { + use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; + let src = temp_dir("embedded-rejected-rating-test"); + let px = [128u8; 40 * 30 * 3]; + + // Case 1: EXIF rating -1 + let exif = lightcraft_meta::write_exif(&lightcraft_meta::Metadata { rating: Some(-1), ..Default::default() }); + let meta = EncodeMeta { exif: Some(&exif), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("exif_rejected.jpg"), &bytes).unwrap(); + + // Case 2: XMP rating -1 + let xmp = r#""#; + let meta = EncodeMeta { xmp: Some(xmp), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("xmp_rejected.jpg"), &bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 2); + let exif_p = s.catalog.photos().find(|p| p.file_name == "exif_rejected.jpg").unwrap(); + assert_eq!(exif_p.rating, 0); + assert_eq!(exif_p.flag, lightcraft_catalog::Flag::Reject); + + let xmp_p = s.catalog.photos().find(|p| p.file_name == "xmp_rejected.jpg").unwrap(); + assert_eq!(xmp_p.rating, 0); + assert_eq!(xmp_p.flag, lightcraft_catalog::Flag::Reject); + + let _ = std::fs::remove_dir_all(&src); +} diff --git a/crates/meta/src/exif.rs b/crates/meta/src/exif.rs index 2b2ea1d131..f2c9ceef4a 100644 --- a/crates/meta/src/exif.rs +++ b/crates/meta/src/exif.rs @@ -67,7 +67,10 @@ pub fn from_tiff(tiff: &Tiff) -> Metadata { m.lens_spec = nikon_lens_spec(exif, m.make.as_deref(), tiff.order); } m.orientation = ifd0.and_then(|i| i.u16(t::ORIENTATION)).filter(|v| (1..=8).contains(v)).map(Orientation::from_exif); - m.rating = ifd0.and_then(|i| i.i64(t::RATING)).map(|r| r.clamp(-1, 5) as i8); + m.rating = ifd0.and_then(|i| i.i64(t::RATING)).map(|r| { + let r = if r == 65535 || r == -1 { -1 } else { r }; + r.clamp(-1, 5) as i8 + }); m.exposure_time = pos(either(t::EXPOSURE_TIME).and_then(|v| v.get_f64(0))) .or_else(|| exif.and_then(|e| e.f64(t::SHUTTER_SPEED_VALUE)).filter(|v| v.abs() < 64.0).map(|tv| 2f64.powf(-tv))); @@ -444,6 +447,9 @@ pub fn write_exif(meta: &Metadata) -> Vec { ifd0.set(tag, v); } } + if let Some(r) = meta.rating { + ifd0.set(t::RATING, if r < 0 { Value::Short(vec![0xffff]) } else { Value::Short(vec![r as u16]) }); + } let mut ex = IfdBuilder::new(); ex.set(t::EXIF_VERSION, Value::Undefined(b"0232".to_vec())); let r = |v: Option| v.filter(|v| v.is_finite() && *v > 0.0).map(|v| Value::Rational(vec![rational(v)])); @@ -503,6 +509,7 @@ mod write_tests { focal_length: Some(35.0), lens_model: Some("35mm F2".into()), gps: Some(Gps { latitude: 43.7904, longitude: -110.6818, altitude: Some(2000.0) }), + rating: Some(4), ..Default::default() }; let back = read_exif(&write_exif(&m)); @@ -515,7 +522,11 @@ mod write_tests { assert!((back.f_number.unwrap() - 2.8).abs() < 1e-6); assert!((back.exposure_time.unwrap() - 0.004).abs() < 1e-9); assert_eq!(back.lens_model, m.lens_model); + assert_eq!(back.rating, Some(4)); let g = back.gps.unwrap(); assert!((g.latitude - 43.7904).abs() < 1e-5 && (g.longitude + 110.6818).abs() < 1e-5, "{g:?}"); + + let rejected = read_exif(&write_exif(&Metadata { rating: Some(-1), ..Default::default() })); + assert_eq!(rejected.rating, Some(-1)); } } From 7aeb1561ed574db776c9aae10166282307082ba7 Mon Sep 17 00:00:00 2001 From: Sebastian Berschneider Date: Mon, 19 Oct 2026 15:25:25 +0200 Subject: [PATCH 03/57] Import: support embedded XMP in PNG/WebP and refine XMP rating detection - Check specifically for xmp:Rating property in embedded XMP before merging EXIF rating - Retain embedded XMP during import for PNG and WebP files - Add import tests for embedded-XMP PNG/WebP and EXIF rating with unrelated XMP text --- crates/engine/src/files.rs | 9 ++++- crates/engine/src/import.rs | 2 +- crates/engine/src/tests_import.rs | 55 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index 81d41d0a09..f51683755b 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -125,9 +125,16 @@ pub fn embedded_lens(raw: &lightcraft_raw::RawInfo) -> Option bool { + if x.contains("xmp:Rating") || x.contains("xap:Rating") || x.contains(":Rating=") || x.contains(":Rating>") || x.contains(":Rating ") { + return true; + } + lightcraft_meta::parse_xmp(x).ok().and_then(|d| d.metadata.rating).is_some() +} + fn embedded_or_exif_xmp(bytes: &[u8], m: &lightcraft_meta::Metadata) -> Option { match lightcraft_meta::embedded(bytes).xmp { - Some(x) if !x.contains("Rating") && m.rating.is_some() => { + Some(x) if !xmp_has_rating(&x) && m.rating.is_some() => { let fresh = lightcraft_meta::write_xmp(m, None); lightcraft_meta::merge_xmp(&x, &fresh, lightcraft_meta::MergeRules { owned_if_present: &["xmp:Rating"], ..Default::default() }) .ok() diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rs index 2b5d7aeda0..96e8db7788 100644 --- a/crates/engine/src/import.rs +++ b/crates/engine/src/import.rs @@ -1063,7 +1063,7 @@ impl ImportJob { // the XMP sidecar (or a file's embedded XMP), read before copying: its capture time files // and names the copy when the file itself has none let raw = info.kind == MediaKind::Raw; - let has_embedded_xmp = raw || matches!(info.format.as_str(), "JPEG" | "JPG" | "TIFF" | "TIF"); + let has_embedded_xmp = raw || matches!(info.format.to_ascii_uppercase().as_str(), "JPEG" | "JPG" | "TIFF" | "TIF" | "PNG" | "WEBP"); let packet = crate::sidecar::find_sidecar(&path, self.naming) .and_then(|f| std::fs::read_to_string(f).ok()) .or_else(|| info.xmp.clone().filter(|_| has_embedded_xmp)); diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index 2ac89d4661..1ab0b24b87 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -1865,3 +1865,58 @@ fn import_preserves_embedded_rejected_rating() { let _ = std::fs::remove_dir_all(&src); } + +#[test] +fn import_preserves_embedded_xmp_png_and_webp() { + use lightcraft_catalog::ColorLabel; + use lightcraft_codecs::{EncodeImage, EncodeMeta, Samples, encode_png, encode_webp_lossless}; + let src = temp_dir("embedded-xmp-png-webp-test"); + let px = [128u8; 40 * 30 * 3]; + + // PNG with embedded XMP rating and label + let png_xmp = r#""#; + let png_meta = EncodeMeta { xmp: Some(png_xmp), ..Default::default() }; + let png_bytes = encode_png(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), &png_meta).unwrap(); + std::fs::write(src.join("embedded.png"), &png_bytes).unwrap(); + + // WebP with embedded XMP rating and label + let webp_xmp = r#""#; + let webp_meta = EncodeMeta { xmp: Some(webp_xmp), ..Default::default() }; + let webp_bytes = encode_webp_lossless(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), &webp_meta).unwrap(); + std::fs::write(src.join("embedded.webp"), &webp_bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 2); + + let png_photo = s.catalog.photos().find(|p| p.file_name == "embedded.png").unwrap(); + assert_eq!(png_photo.rating, 4); + assert_eq!(png_photo.label, Some(ColorLabel::Red)); + + let webp_photo = s.catalog.photos().find(|p| p.file_name == "embedded.webp").unwrap(); + assert_eq!(webp_photo.rating, 2); + assert_eq!(webp_photo.label, Some(ColorLabel::Blue)); + + let _ = std::fs::remove_dir_all(&src); +} + +#[test] +fn import_preserves_exif_rating_when_xmp_has_unrelated_rating_text() { + use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; + let src = temp_dir("exif-rating-unrelated-xmp-test"); + let px = [128u8; 40 * 30 * 3]; + + let exif = lightcraft_meta::write_exif(&lightcraft_meta::Metadata { rating: Some(5), ..Default::default() }); + let xmp = r#"100Rating guide"#; + let meta = EncodeMeta { exif: Some(&exif), xmp: Some(xmp), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("iso_and_desc_rating.jpg"), &bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.join("iso_and_desc_rating.jpg").to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 1); + let p = s.catalog.photos().next().unwrap(); + assert_eq!(p.rating, 5); + + let _ = std::fs::remove_dir_all(&src); +} From a5e943364187b69a37a908ed7182a4e17a684ab1 Mon Sep 17 00:00:00 2001 From: Sebastian Berschneider Date: Wed, 21 Oct 2026 07:31:07 +0200 Subject: [PATCH 04/57] Import: ignore embedded develop adjustments for rendered images - Clear parsed develop settings and warnings when XMP packet is embedded in a non-raw image (JPEG, TIFF, PNG, WebP) - Keep develop adjustments for raw/DNG files or external sidecars - Add test verifying that a JPEG with embedded rating and crs:Exposure2012 imports with rating and default develop state --- crates/engine/src/import.rs | 17 +++++++++++++---- crates/engine/src/tests_import.rs | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/import.rs b/crates/engine/src/import.rs index 96e8db7788..5abf63cdad 100644 --- a/crates/engine/src/import.rs +++ b/crates/engine/src/import.rs @@ -1064,17 +1064,26 @@ impl ImportJob { // and names the copy when the file itself has none let raw = info.kind == MediaKind::Raw; let has_embedded_xmp = raw || matches!(info.format.to_ascii_uppercase().as_str(), "JPEG" | "JPG" | "TIFF" | "TIF" | "PNG" | "WEBP"); - let packet = crate::sidecar::find_sidecar(&path, self.naming) - .and_then(|f| std::fs::read_to_string(f).ok()) - .or_else(|| info.xmp.clone().filter(|_| has_embedded_xmp)); + let sidecar_file = crate::sidecar::find_sidecar(&path, self.naming).and_then(|f| std::fs::read_to_string(f).ok()); + let from_file = sidecar_file.is_none(); + let packet = sidecar_file.or_else(|| info.xmp.clone().filter(|_| has_embedded_xmp)); let target = crate::crs::Target::for_file(info.kind, &info.format, info.preview_only.is_some(), &info.meta.camera); - let sidecar = packet.and_then(|x| match crate::sidecar::parse_sidecar(&x, target) { + let mut sidecar = packet.and_then(|x| match crate::sidecar::parse_sidecar(&x, target) { Ok(sc) => Some(sc), Err(e) => { log::warn!("import {path}: XMP: {e}"); None } }); + // Embedded XMP on a rendered file (JPEG, TIFF, PNG, WebP) has develop adjustments + // already baked into the pixels; only raws/DNGs keep foreign develop settings from embedded XMP. + if from_file + && !raw + && let Some(sc) = &mut sidecar + { + sc.develop = None; + sc.warnings.clear(); + } if info.captured.is_none() { info.captured = sidecar.as_ref().and_then(|sc| sc.captured.clone()); } diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index 1ab0b24b87..3993f81b15 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -1920,3 +1920,28 @@ fn import_preserves_exif_rating_when_xmp_has_unrelated_rating_text() { let _ = std::fs::remove_dir_all(&src); } + +#[test] +fn import_rendered_file_ignores_embedded_develop_settings() { + use lightcraft_codecs::{ChromaSubsampling, EncodeImage, EncodeMeta, Samples, encode_jpeg}; + let src = temp_dir("embedded-rendered-develop-test"); + let px = [128u8; 40 * 30 * 3]; + + // A JPEG with embedded XMP containing rating and crs:Exposure2012="+1.00" + let xmp = r#""#; + let meta = EncodeMeta { xmp: Some(xmp), ..Default::default() }; + let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); + std::fs::write(src.join("rendered_with_crs.jpg"), &bytes).unwrap(); + + let mut s = Session::new().with_fs(); + let r = s.execute("library.import", &json!({"paths": [src.join("rendered_with_crs.jpg").to_string_lossy()]})).unwrap(); + assert_eq!(ids(&r, "imported"), 1); + let p = s.catalog.photos().next().unwrap(); + // Rating is imported from embedded XMP + assert_eq!(p.rating, 3); + // Develop settings from embedded XMP are ignored for rendered files (already baked into pixels) + assert_eq!(p.develop.light.exposure, 0.0); + assert_eq!(p.develop, std::sync::Arc::new(p.camera_defaults())); + + let _ = std::fs::remove_dir_all(&src); +} From d6575581ed03215164fc6cee0257986705a8a474 Mon Sep 17 00:00:00 2001 From: Sebastian Berschneider Date: Thu, 22 Oct 2026 22:25:39 +0200 Subject: [PATCH 05/57] Import: use parsed XMP rating in xmp_has_rating --- crates/engine/src/files.rs | 3 --- crates/engine/src/tests_import.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/engine/src/files.rs b/crates/engine/src/files.rs index ccd04c7756..6b9699a316 100644 --- a/crates/engine/src/files.rs +++ b/crates/engine/src/files.rs @@ -126,9 +126,6 @@ pub fn embedded_lens(raw: &lightcraft_raw::RawInfo) -> Option bool { - if x.contains("xmp:Rating") || x.contains("xap:Rating") || x.contains(":Rating=") || x.contains(":Rating>") || x.contains(":Rating ") { - return true; - } lightcraft_meta::parse_xmp(x).ok().and_then(|d| d.metadata.rating).is_some() } diff --git a/crates/engine/src/tests_import.rs b/crates/engine/src/tests_import.rs index a7045863f8..3506df90f2 100644 --- a/crates/engine/src/tests_import.rs +++ b/crates/engine/src/tests_import.rs @@ -2208,7 +2208,7 @@ fn import_preserves_exif_rating_when_xmp_has_unrelated_rating_text() { let px = [128u8; 40 * 30 * 3]; let exif = lightcraft_meta::write_exif(&lightcraft_meta::Metadata { rating: Some(5), ..Default::default() }); - let xmp = r#"100Rating guide"#; + let xmp = r#"100Rating guide mentioning xmp:Rating"#; let meta = EncodeMeta { exif: Some(&exif), xmp: Some(xmp), ..Default::default() }; let bytes = encode_jpeg(&EncodeImage::new(40, 30, 3, Samples::U8(&px)), 90, ChromaSubsampling::S444, &meta).unwrap(); std::fs::write(src.join("iso_and_desc_rating.jpg"), &bytes).unwrap(); From 29b5b3811dd94b0f54b8698f6621da74def2cd3a Mon Sep 17 00:00:00 2001 From: OneSlips Date: Sat, 17 Oct 2026 00:31:01 +1000 Subject: [PATCH 06/57] UI-PANEL-RESTORE: closing a tool panel gives the panel back as it was Opening Masking, Crop, Remove or Red Eye from the Edit panel and closing it again left no panel at all: the photo jumped sideways and the sliders had to be found again. The panel shown before a tool panel is now remembered (UiState::note_right / leave_tool) and put back in the same frame when the tool closes, by its button, its shortcut or Done: the Edit panel comes back at the same width, the photo stays where it was, and each panel keeps its own scroll position. A panel that was hidden stays hidden. ui.set keeps what is remembered. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 3b3daebb4ee1832fe1f81fb8734e679f433cab7c) --- crates/ui-egui/src/control.rs | 3 + crates/ui-egui/src/lib.rs | 4 + crates/ui-egui/src/menus.rs | 9 +- crates/ui-egui/src/panels/right.rs | 3 +- crates/ui-egui/src/state.rs | 43 ++++++++- crates/ui-egui/src/tests_panel_restore.rs | 106 ++++++++++++++++++++++ 6 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/tests_panel_restore.rs diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 7e04f1356d..14b569c9e7 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -387,6 +387,9 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest } u.collapsed_sidebar.clear(); u.toast = app.ui.toast.clone(); + // the panel a tool panel took the place of, to put back when it closes, survives a ui.set + u.tool_return = app.ui.tool_return; + u.right_seen = app.ui.right_seen; u.dialog = app.ui.dialog.clone(); u.status = app.ui.status.clone(); crate::docking::cancel_replaced_gesture(app, u.docking.as_ref()); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 4fc43172ce..0fb89a88e8 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -158,6 +158,8 @@ mod tests_offline; #[cfg(test)] mod tests_open_lightroom; #[cfg(test)] +mod tests_panel_restore; +#[cfg(test)] mod tests_panels; #[cfg(test)] mod tests_preset_favorites; @@ -1581,6 +1583,8 @@ impl LightcraftApp { ctx.send_viewport_cmd(egui::ViewportCommand::Close); } self.library_changed(&ctx); + // (a tool panel opened some other way still remembers the panel it took the place of) + self.ui.note_right(); // panels set it again this frame while the pointer rests on a preset or profile self.hover_preview = None; self.ai_mask_detail(&ctx); diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 8c249dd365..1aeb29b743 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -290,8 +290,11 @@ pub const UI_COMMANDS: &[UiCommand] = &[ ]; fn panel(app: &mut LightcraftApp, ctx: &egui::Context, p: RightPanel, name: &str) { + app.ui.note_right(); if app.ui.right == p && crate::docking::exposed(app, crate::docking::Panel::Tools) { - app.ui.right = RightPanel::None; + // a tool closing puts back the panel shown before it (in the same frame: no flash, no + // jump), or leaves the panel hidden when it was + app.ui.right = if p.is_tool() { app.ui.leave_tool() } else { RightPanel::None }; app.toast(ctx, crate::i18n::tr_format!("{name} Off", name = crate::i18n::tr(name))); } else { app.ui.right = p; @@ -303,6 +306,7 @@ fn panel(app: &mut LightcraftApp, ctx: &egui::Context, p: RightPanel, name: &str if p != RightPanel::Masking && app.ui.tool != "wbPicker" { app.ui.tool.clear(); } + app.ui.note_right(); let _ = app.session.end_interaction(); } @@ -1307,7 +1311,8 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option bool { + matches!(self, RightPanel::Crop | RightPanel::Remove | RightPanel::Masking | RightPanel::RedEye) + } + pub fn is_edit_tool(self) -> bool { matches!(self, RightPanel::Edit | RightPanel::Profiles | RightPanel::Crop | RightPanel::Remove | RightPanel::Masking | RightPanel::RedEye) } @@ -801,6 +807,13 @@ pub struct UiState { /// The right panel F8 (`view.rightPanel`) hid, which the next F8 shows again. #[serde(skip)] pub right_hidden: RightPanel, + /// The panel on show before a tool panel ([`RightPanel::is_tool`]) took its place, put back + /// when the tool closes ([`RightPanel::None`]: the panel was hidden, and stays hidden). + #[serde(skip)] + pub tool_return: Option, + /// The panel [`UiState::note_right`] last saw. + #[serde(skip)] + pub right_seen: RightPanel, /// Widths of the left sidebar and of the right panel in points (dragging their inner edge /// resizes them; within [`LEFT_WIDTH`] / [`RIGHT_WIDTH`]). pub left_width: f32, @@ -1477,6 +1490,32 @@ impl SyncCounts { } } +impl UiState { + /// Notes the panel on show: a tool panel opened from another panel (or from none) remembers + /// that one, to put it back when the tool closes; any other panel forgets it. + pub fn note_right(&mut self) { + if self.right == self.right_seen { + return; + } + if self.right.is_tool() { + if !self.right_seen.is_tool() { + self.tool_return = Some(self.right_seen); + } + } else { + self.tool_return = None; + } + self.right_seen = self.right; + } + + /// The panel to show when the tool panel on show closes: the one shown before it, or none + /// when the panel was hidden (Edit when nothing is known). + pub fn leave_tool(&mut self) -> RightPanel { + self.note_right(); + let back = self.tool_return.take().unwrap_or(RightPanel::Edit); + if back.is_tool() { RightPanel::Edit } else { back } + } +} + impl Default for UiState { fn default() -> Self { UiState { @@ -1493,6 +1532,8 @@ impl Default for UiState { right_width: RIGHT_WIDTH.default, right: RightPanel::Edit, right_hidden: RightPanel::None, + tool_return: None, + right_seen: RightPanel::Edit, presets: false, preset_thumbs: false, filmstrip: true, diff --git a/crates/ui-egui/src/tests_panel_restore.rs b/crates/ui-egui/src/tests_panel_restore.rs new file mode 100644 index 0000000000..dd952145f4 --- /dev/null +++ b/crates/ui-egui/src/tests_panel_restore.rs @@ -0,0 +1,106 @@ +//! The panel a tool takes the place of comes back when the tool closes (item 12 of the evening +//! retest): open Edit → Masking (or Crop) → close it → Edit again, at the same width and scroll +//! position, with the photo where it was; a hidden panel stays hidden. + +use std::time::Duration; + +use serde_json::json; + +use crate::headless::Headless; +use crate::state::RightPanel; +use crate::{LightcraftApp, Services}; + +const T: Duration = Duration::from_secs(20); +const SETTLE: Duration = Duration::from_secs(120); + +fn detail() -> Headless { + let services = Services { png: None, ..Default::default() }; + let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), services); + let mut h = Headless::new(app, [1400.0, 900.0], 1.0); + let r = h.request("ui.set", json!({"view": "detail", "right": "edit"}), T); + assert_eq!(r["ok"], true, "{r}"); + h.settle(SETTLE); + h +} + +fn exec(h: &mut Headless, command: &str) { + let r = h.request("engine.execute", json!({"command": command, "params": {}}), T); + assert_eq!(r["ok"], true, "{command}: {r}"); + h.step(); + h.step(); +} + +fn widget(h: &Headless, id: &str) -> Option { + h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r) +} + +/// The Edit panel's first slider on show (its id and where it is: it moves when the panel scrolls). +fn first_slider(h: &Headless) -> (String, egui::Rect) { + let panel = widget(h, "panel:right_panel").expect("the right panel"); + h.app + .widgets + .iter() + .filter(|(w, r)| w.starts_with("slider:") && panel.contains_rect(*r)) + .min_by(|a, b| a.1.top().total_cmp(&b.1.top())) + .map(|(w, r)| (w.clone(), *r)) + .expect("a slider in the Edit panel") +} + +#[test] +fn the_edit_panel_comes_back_after_masking_and_crop_where_it_was() { + let mut h = detail(); + // scroll the Edit panel down a little (the wheel scrolls what the pointer is over) + let panel = widget(&h, "panel:right_panel").expect("the right panel"); + h.request("ui.move", json!({"x": panel.center().x, "y": panel.center().y}), T); + let r = h.request("ui.scroll", json!({"dy": -300.0}), T); + assert_eq!(r["ok"], true, "{r}"); + for _ in 0..60 { + h.step(); + } + let (slider, at) = first_slider(&h); + let photo = widget(&h, "canvas:image").expect("the photo"); + for tool in ["panel.masking", "panel.crop", "panel.remove"] { + exec(&mut h, tool); + assert!(h.app.ui.right.is_tool(), "{tool}: {:?}", h.app.ui.right); + assert_eq!(widget(&h, "panel:right_panel"), Some(panel), "{tool}: the panel keeps its place and width"); + // the same button again closes the tool: Edit is back, as it was + exec(&mut h, tool); + assert_eq!(h.app.ui.right, RightPanel::Edit, "{tool}: the Edit panel comes back"); + assert_eq!(widget(&h, "panel:right_panel"), Some(panel), "{tool}: same place and width"); + assert_eq!(widget(&h, "canvas:image"), Some(photo), "{tool}: the photo didn't move"); + assert_eq!(widget(&h, &slider), Some(at), "{tool}: Edit kept its scroll position"); + } + // Masking, then Crop from it, then Crop closed: still Edit + exec(&mut h, "panel.masking"); + exec(&mut h, "panel.crop"); + exec(&mut h, "panel.crop"); + assert_eq!(h.app.ui.right, RightPanel::Edit); + // Return (Done) in a tool also goes back + exec(&mut h, "panel.masking"); + exec(&mut h, "tool.done"); + assert_eq!(h.app.ui.right, RightPanel::Edit); +} + +#[test] +fn a_hidden_panel_stays_hidden_after_a_tool() { + let mut h = detail(); + exec(&mut h, "panel.close"); + assert_eq!(h.app.ui.right, RightPanel::None); + let photo = widget(&h, "canvas:image").expect("the photo"); + for tool in ["panel.masking", "panel.crop"] { + exec(&mut h, tool); + assert!(h.app.ui.right.is_tool(), "{tool} shows"); + exec(&mut h, tool); + assert_eq!(h.app.ui.right, RightPanel::None, "{tool}: nothing shows again"); + h.settle(SETTLE); + assert_eq!(widget(&h, "canvas:image"), Some(photo), "{tool}: the photo is where it was"); + } + exec(&mut h, "panel.masking"); + exec(&mut h, "tool.done"); + assert_eq!(h.app.ui.right, RightPanel::None, "Done: hidden as before"); + // a panel picked meanwhile is what comes back: Info → Masking → closed = Info + exec(&mut h, "panel.info"); + exec(&mut h, "panel.masking"); + exec(&mut h, "panel.masking"); + assert_eq!(h.app.ui.right, RightPanel::Info); +} From 283d65852fb6a67bb8900f9b92f016cbdc3d404f Mon Sep 17 00:00:00 2001 From: OneSlips Date: Sun, 25 Oct 2026 06:46:02 +1000 Subject: [PATCH 07/57] KEY-INFO: I toggled off brings back exactly what was there before, closed included (test notes 2026-10-24 note 21) Every panel toggle (I, M, R, Q, the tool strip's buttons) remembers what the right column showed when it opened the panel and puts exactly that back when toggled off: Edit -> I -> I = Edit, Masks -> I -> I = Masks, closed -> I -> I = closed. A tool opened from another tool goes back to that tool (UiState::toggle_panel). Co-Authored-By: Claude Opus 5.5 (cherry picked from commit d5ec632329a60d6526549b71ae2907c09a0d74d0) --- crates/ui-egui/src/menus.rs | 10 ++--- crates/ui-egui/src/state.rs | 46 +++++++++++++++++++++++ crates/ui-egui/src/tests_panel_restore.rs | 41 +++++++++++++++++++- 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 1aeb29b743..b2e880aecb 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -290,14 +290,12 @@ pub const UI_COMMANDS: &[UiCommand] = &[ ]; fn panel(app: &mut LightcraftApp, ctx: &egui::Context, p: RightPanel, name: &str) { - app.ui.note_right(); - if app.ui.right == p && crate::docking::exposed(app, crate::docking::Panel::Tools) { - // a tool closing puts back the panel shown before it (in the same frame: no flash, no - // jump), or leaves the panel hidden when it was - app.ui.right = if p.is_tool() { app.ui.leave_tool() } else { RightPanel::None }; + // toggled off: back to exactly what the right column showed before (in the same frame: no flash, no jump), + // closed when it was closed (note 21) + let exposed = crate::docking::exposed(app, crate::docking::Panel::Tools); + if !app.ui.toggle_panel(p, exposed) { app.toast(ctx, crate::i18n::tr_format!("{name} Off", name = crate::i18n::tr(name))); } else { - app.ui.right = p; app.toast(ctx, crate::i18n::tr_format!("{name} On", name = crate::i18n::tr(name))); if p.is_edit_tool() && !matches!(app.ui.view, ViewMode::Detail) { app.ui.view = ViewMode::Detail; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ba531918ee..60a99b8891 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -811,6 +811,11 @@ pub struct UiState { /// when the tool closes ([`RightPanel::None`]: the panel was hidden, and stays hidden). #[serde(skip)] pub tool_return: Option, + /// The panel a toggle (a panel key or button: I, M, R, Q…) opened, with what the right column showed before it + /// and that one's [`UiState::tool_return`]: toggling it off puts back exactly that, closed included (test notes + /// 2026-10-24 note 21). Forgotten once another panel is shown. + #[serde(skip)] + pub toggle_return: Option<(RightPanel, RightPanel, Option)>, /// The panel [`UiState::note_right`] last saw. #[serde(skip)] pub right_seen: RightPanel, @@ -1497,6 +1502,9 @@ impl UiState { if self.right == self.right_seen { return; } + if self.toggle_return.is_some_and(|(opened, ..)| opened != self.right) { + self.toggle_return = None; + } if self.right.is_tool() { if !self.right_seen.is_tool() { self.tool_return = Some(self.right_seen); @@ -1511,9 +1519,46 @@ impl UiState { /// when the panel was hidden (Edit when nothing is known). pub fn leave_tool(&mut self) -> RightPanel { self.note_right(); + if let Some(back) = self.untoggle() { + return back; + } let back = self.tool_return.take().unwrap_or(RightPanel::Edit); if back.is_tool() { RightPanel::Edit } else { back } } + + /// A panel toggle (`panel.info`, `panel.masking`…) for `p`: when `p` is on show (`exposed`: not hidden behind + /// another dock tab) it goes and the right column shows exactly what it showed before the toggle opened it, or + /// stays closed when it was (note 21); otherwise `p` comes up and what was there is remembered. Returns whether + /// `p` is now on. + pub fn toggle_panel(&mut self, p: RightPanel, exposed: bool) -> bool { + self.note_right(); + if self.right == p && exposed { + self.right = match self.untoggle() { + Some(back) => back, + None if p.is_tool() => self.leave_tool(), + None => RightPanel::None, + }; + self.note_right(); + false + } else { + let saved = (p, if exposed || self.right != p { self.right } else { RightPanel::None }, self.tool_return); + self.right = p; + self.note_right(); + self.toggle_return = Some(saved); + true + } + } + + /// What the toggle that opened the panel on show replaced (see [`UiState::toggle_panel`]), with its own tool + /// memory put back, or `None` when that panel wasn't opened by a toggle. + fn untoggle(&mut self) -> Option { + let (_, before, tool_return) = self.toggle_return.filter(|(opened, ..)| *opened == self.right)?; + self.toggle_return = None; + self.tool_return = tool_return; + // seen already: `note_right` must not take the panel being left for the one this came back from + self.right_seen = before; + Some(before) + } } impl Default for UiState { @@ -1533,6 +1578,7 @@ impl Default for UiState { right: RightPanel::Edit, right_hidden: RightPanel::None, tool_return: None, + toggle_return: None, right_seen: RightPanel::Edit, presets: false, preset_thumbs: false, diff --git a/crates/ui-egui/src/tests_panel_restore.rs b/crates/ui-egui/src/tests_panel_restore.rs index dd952145f4..640428a6c9 100644 --- a/crates/ui-egui/src/tests_panel_restore.rs +++ b/crates/ui-egui/src/tests_panel_restore.rs @@ -70,10 +70,12 @@ fn the_edit_panel_comes_back_after_masking_and_crop_where_it_was() { assert_eq!(widget(&h, "canvas:image"), Some(photo), "{tool}: the photo didn't move"); assert_eq!(widget(&h, &slider), Some(at), "{tool}: Edit kept its scroll position"); } - // Masking, then Crop from it, then Crop closed: still Edit + // Masking, then Crop from it, then Crop closed: exactly what was there before, Masking (note 21); then Edit exec(&mut h, "panel.masking"); exec(&mut h, "panel.crop"); exec(&mut h, "panel.crop"); + assert_eq!(h.app.ui.right, RightPanel::Masking); + exec(&mut h, "panel.masking"); assert_eq!(h.app.ui.right, RightPanel::Edit); // Return (Done) in a tool also goes back exec(&mut h, "panel.masking"); @@ -104,3 +106,40 @@ fn a_hidden_panel_stays_hidden_after_a_tool() { exec(&mut h, "panel.masking"); assert_eq!(h.app.ui.right, RightPanel::Info); } + +/// "I" toggles the Info panel; pressing it again brings back exactly what the right column showed before, closed +/// included (test notes 2026-10-24 note 21: the Edit sliders stayed gone). +#[test] +fn info_toggled_off_brings_back_exactly_what_was_there() { + let mut h = detail(); + assert_eq!(h.app.ui.right, RightPanel::Edit); + // the key, as the user pressed it + let key = |h: &mut Headless| { + let r = h.request("ui.key", json!({"key": "I"}), T); + assert_eq!(r["ok"], true, "{r}"); + h.step(); + h.step(); + }; + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::Info); + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::Edit, "Edit → I → I = Edit"); + exec(&mut h, "panel.masking"); + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::Info); + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::Masking, "Masks → I → I = Masks"); + // and Masks still closes back to Edit + exec(&mut h, "panel.masking"); + assert_eq!(h.app.ui.right, RightPanel::Edit); + for panel in ["panel.keywords", "panel.versions", "panel.activity"] { + exec(&mut h, panel); + exec(&mut h, panel); + assert_eq!(h.app.ui.right, RightPanel::Edit, "{panel} toggled off: Edit again"); + } + exec(&mut h, "panel.close"); + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::Info); + key(&mut h); + assert_eq!(h.app.ui.right, RightPanel::None, "closed → I → I = closed"); +} From 3245ad02ea56c7c3b74f61e0e6f5d66354824b09 Mon Sep 17 00:00:00 2001 From: OneSlips Date: Mon, 26 Oct 2026 01:01:23 +1000 Subject: [PATCH 08/57] KEY-INFO: checklist rows, revision line and What's New for panels that come back as they were Co-Authored-By: Claude Opus 5.5 --- docs/parity-checklist.md | 7 ++++--- docs/whats-new.md | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 080680b9ff..f854de9e81 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -1,6 +1,6 @@ # Lightroom parity checklist -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-26 · **Change:** minor (LR-BEHAV-PANEL-RESIZE, KEY-INFO: closing a tool panel or toggling a panel off puts back exactly what the right column showed before; KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 go to the next / previous keyword set; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings; KEYC-METADATA: ⌘K / Ctrl+K Add Keywords; LRC-DEV-HISTOGRAM-DRAG: the histogram's five tonal zones — hover for the value, drag to adjust the Basic control the press locked, double-click to reset; LR-VIEW-HISTOGRAM note updated; MENU-BAR: on macOS a menu item that yields its key to a focused text field or to shortcut recording really lets it go; LR-MERGE-HDR / LR-MERGE-PANO: Lanczos-3 warps; LR-IMP-LOCAL: browsing from the sidebar records the folder; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LR-IMP-ADD-DIALOG: hierarchical import album destination reconciled with main, #2362; KEY-SLIDER-NUDGE: vertical wheel nudges need a click or drag in the row; leaving it disarms them; LR-EDIT-OPTICS-PROFILE: Fujifilm nine-knot lens tables read at the plain radius; LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict; LRC-LIB-LIBFOLDERS, LR-BEHAV-BG-TASKS: Synchronize Folder's scan shows its folder listing and stops it on ✕; LRC-LIB-LIBFOLDERS: Synchronize Folder says a folder is up to date; LR-LIB-STACK: filmstrip stack badge click; LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused; LRC-LIB-COMPARE: the Info panel labels the active photo while culling, #2398; KEYC-RATING: `\` shows / hides the Filter Bar in the grids; LR-VIEW-PHOTOGRID: the grid reads only the photos an import batch or an edit touched, not the whole list; earlier: LRC-PRINT-PAGE: Print Page Options; LR-META-XMP: fewer false unimported-XMP warnings) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6 The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what we have and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good @@ -474,7 +474,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts). | LR-BEHAV-SIDEBAR-HIDE | Show and hide left-sidebar sections | P2 | ✅ | `cmd:view.sidebarSection`, `cmd:view.sidebarReset`, `crates/ui-egui/src/sidebar.rs`, `crates/ui-egui/src/panels/left.rs` (`sections_menu`), `crates/ui-egui/src/menubar.rs`, `crates/ui-egui/src/tests_panels.rs` | View ▸ Sidebar Sections lists Albums, Local, By Date, Folders and Keywords in the sidebar's order, each checked while shown; unchecking one takes its header and rows off the sidebar, checking it puts it back where and how it was (still folded if it was). The same list opens with a right-click on any section header (with Hide This Section first; widgets `sidebarMenu:hide`, `sidebarMenu:section:`, `sidebarMenu:reset`) and on the My Photos title (`sidebarTitle`), which is always there, so hidden sections can always come back. Reset Sidebar Sections (enabled once something changed) shows and opens every section in the usual order. `view.sidebarSection` `{section, show?, collapsed?}` flips shown / hidden when neither flag is given and refuses an unknown section or a flag that is not true / false. Hiding the section of what the grid shows (an album, a keyword filter) leaves the grid as it is; an album made while Albums is hidden or folded brings Albums back, open. Kept with the UI state (`sidebar`). My Photos itself can't be hidden | | LR-BEHAV-SIDEBAR-REORDER | Reorder left-sidebar sections | P2 | ✅ | `cmd:view.sidebarMoveSection`, `crates/ui-egui/src/sidebar.rs` (`move_before`, `move_by`), `crates/ui-egui/src/panels/left.rs` (`section_drag`, `section_drop_before`, `section_drag_feedback`), `crates/ui-egui/src/tests_panels.rs` | drag a section by its header: its name follows the pointer, a line (`sidebarSectionDrop`) shows the gap it would go to (above the section whose upper half the pointer is over, or below the last), releasing over the sidebar moves it there, Esc or releasing elsewhere leaves it; the sidebar scrolls when the drag nears its top or bottom edge, also over a pinned header (a section picked up by the pinned header scrolls once the pointer has left it). A press on a header's button is never a section drag. A click on the header still folds the section, and an album dragged onto the Albums header is still an album drag. The header's menu has Move Up / Move Down (`sidebarMenu:moveUp` / `moveDown`), one shown section at a time, stepping over hidden ones, disabled at the ends. `view.sidebarMoveSection` `{section, direction: up\|down}` or `{section, before:
\|null}` (null: last) answers `{moved, order}`. The order is kept with the UI state (`sidebar`). Recently Deleted is listed with My Photos (below Picks / Missing Photos), not after the sections. Not here: dragging My Photos, or rows from one section into another | | LR-BEHAV-SIDEBAR-STICKY | Pinned section header and section look | P2 | ✅ | `crates/ui-egui/src/panels/left.rs` (`pinned_header`, `section_header`, `empty_hint`), `crates/ui-egui/src/tests_panels.rs` | while the rows of an open section are in view but its header has scrolled away, a copy of the header (`sidebarSectionPinned:`, with the section's buttons and menu) stays at the top of the sidebar; the next section's header pushes it out; folding from it brings the section's own header into view. Rows scrolled beneath the pinned header are covered by it: an album or photos dropped on the pinned Albums header go to the top level / nowhere, never to the row under it; folding from it keeps the sideways scroll. Sections are told apart by a hairline in the gap above each; the fold chevron sits in the gutter, in the column of the rows' triangles (`sidebarSectionChevron:`); a header highlights under the pointer; a folded section shows how many top-level rows it holds (`sidebarSectionCount:`, with View ▸ Photo Counts); a count of 0 is fainter. Not here: a height of its own per section (one scroll area serves the whole sidebar), a count for Recently Added, Local's Browse Folder… as a header button | -| LR-BEHAV-PANEL-RESIZE | Resizable side panels | P1 | ✅ | `crates/ui-egui/src/panels/mod.rs` (`resizable_side`), `crates/ui-egui/src/state.rs` (`LEFT_WIDTH`, `RIGHT_WIDTH`), `crates/ui-egui/src/tests_panels.rs` | drag the left sidebar's right edge (200–480 pt) or the right panel's left edge (250–520 pt); the photo area keeps ≥ 360 pt; widths are kept across panels, views and restarts (`leftWidth` / `rightWidth` in the UI state); the Presets column stays fixed | +| LR-BEHAV-PANEL-RESIZE | Resizable side panels | P1 | ✅ | `crates/ui-egui/src/panels/mod.rs` (`resizable_side`), `crates/ui-egui/src/state.rs` (`LEFT_WIDTH`, `RIGHT_WIDTH`), `crates/ui-egui/src/tests_panels.rs`, `crates/ui-egui/src/tests_panel_restore.rs` | closing a tool panel (Crop, Remove, Masking, Red Eye) puts back the panel shown before it in the same frame, at the same width and scroll position, or leaves it hidden if it was (`UiState::leave_tool`); drag the left sidebar's right edge (200–480 pt) or the right panel's left edge (250–520 pt); the photo area keeps ≥ 360 pt; widths are kept across panels, views and restarts (`leftWidth` / `rightWidth` in the UI state); the Presets column stays fixed | | LR-BEHAV-EMPTY-STATES | Empty states | P1 | ✅ | `crates/ui-egui/src/panels/mod.rs` (`empty_message`, `empty_state`), `crates/ui-egui/src/panels/empty_library.rs`, `cmd:file.addPhotos`, `cmd:file.importLightroom`, `crates/ui-egui/src/tests_empty_library.rs` | each view says why it is empty (no photo selected, filters, an empty folder). A library with no photos (none, or only deleted or browsed ones) opens on the Photo Grid (Square Grid stays) with the sidebar, and the grid and Detail view (not while a folder is browsed under Local) offer Import Photos… (primary) and Import Lightroom Catalog… (desktop) as buttons, with a line saying photos and folders can be dropped into the window and the key Import Photos… is bound to now; the right-hand panel says to import photos first. The top bar has an Import button beside Export in every library. Files dragged over the window dim it and a card says what dropping will do; a drop of photos or folders opens the same import review as File ▸ Import | | LR-BEHAV-TOOLTIPS | Tooltips with shortcuts | P0 | ✅ | `crates/ui-egui/src/panels/bottombar.rs` | | | LR-BEHAV-TEXTFIELD | Text fields behave alike | P1 | 🟡 | `crates/ui-egui/src/text_field.rs`, `crates/ui-egui/src/panels/topbar.rs`, `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/panels/right.rs` (`meta_field`), `crates/ui-egui/src/panels/dialogs.rs`, `crates/ui-egui/src/panels/unnamed.rs` | one shared field: right-click Cut / Copy / Paste / Select All (no Paste in the browser), Esc gives back the text from before the edit, Return / leaving / Esc reported to the caller, optional select-on-focus; agents use `ui.clipboard` (MCP `clipboard`) and `ui.inspect` → `copied`. Used by Search Photos, slider values, the Info panel's metadata fields (multi-line captions), the one-field dialogs (New / Rename Album, New Smart Album, Rename / Merge Keywords, text prompts) and the unnamed faces' name field so far; the other text fields (most dialogs, import, settings, masking, keywords …) still use egui's own and have no menu | @@ -605,7 +605,7 @@ From `06-shortcuts.md` part 1. Evidence is our binding; conflicts are explained | KEY-FULLSCREEN | Full-screen preview — F | P1 | ✅ | `cmd:view.fullScreenPreview` | | | KEY-LIGHTSOUT | Lights Out — Shift+L (Classic's L is Linear Gradient here) | P2 | ✅ | `cmd:view.lightsOut` | On → Dim (80 %) → Off; Esc turns the lights on | | KEY-GRID | Grid — G | P0 | ✅ | `cmd:view.gridToggle`, `cmd:view.photoGrid` | G toggles Photo Grid ↔ Square Grid; both View menu rows show its live shortcut (including remapping/unbinding), with direct grid bindings taking priority; menu clicks still choose the named grid (#2500) | -| KEY-INFO | Info — I | P0 | ✅ | `cmd:panel.info` | | +| KEY-INFO | Info — I | P0 | ✅ | `cmd:panel.info`, `crates/ui-egui/src/tests_panel_restore.rs` | pressing I again brings back exactly what the right column showed before (Edit, Masks…; closed stays closed); every panel key and button does the same (`UiState::toggle_panel`) | | KEY-KEYWORDS | Keywords — K | P0 | ✅ | `cmd:panel.keywords` | | | KEY-CLIPBOARD | Copy / paste edit settings — ⌘C / ⌘V | P0 | ✅ | `cmd:develop.copy`, `cmd:develop.paste`, `crates/ui-egui/src/shortcuts.rs` (`matches`) | ⌘X has nothing to cut outside text fields; on Windows and Linux, where the windowing layer sends Ctrl+C / Ctrl+V as clipboard events rather than key presses, those run the shortcuts too (⇧Insert pastes plainly); there Ctrl+V only arrives while the system clipboard holds text (egui-winit drops it otherwise), so with an empty clipboard Paste Settings needs the menu | | KEY-UNDOREDO | Undo / redo — ⌘Z / ⇧⌘Z | P0 | ✅ | `cmd:edit.undo`, `cmd:edit.redo` | | @@ -799,6 +799,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove | Date | Change | Summary | |---|---|---| +| 2026-10-26 | minor | LR-BEHAV-PANEL-RESIZE, KEY-INFO: closing a tool panel (Crop, Remove, Masking, Red Eye) puts back the panel shown before it, hidden if it was hidden, at the same width and scroll position; a panel key or button (I, M, C, H…) pressed again puts back exactly what the right column showed before it (Edit → I → I = Edit, closed → I → I = closed); status unchanged (✅) | | 2026-10-24 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌥0 / ⌥⇧0 (`keyword.nextSet`, `keyword.previousSet`) go to the next / previous keyword set; status counts unchanged (KEYC-METADATA stays 🟡) | | 2026-10-24 | minor | KEYC-METADATA: ⌘K / Ctrl+K (`panel.addKeywords`, Add Keywords) shows the Keywords panel, opens Keywording and puts the cursor in the Add keyword box; status counts unchanged (KEYC-METADATA stays 🟡) | | 2026-10-24 | patch | LR-LIB-RATING, LR-LIB-DELETE: a slider drag still open when a rating, flag or label takes the photo out of the view, or when the photo is deleted, ends as its own undo step before the selection moves on, as moving to the next photo does; LR-BEHAV-LOCALIZE lists all 18 languages; status unchanged | diff --git a/docs/whats-new.md b/docs/whats-new.md index c6c2592003..b2d5a5ae1b 100644 --- a/docs/whats-new.md +++ b/docs/whats-new.md @@ -1,5 +1,13 @@ # What's new in LightCraft +## 2026-10-26 + +### Panels come back as they were +- Close Masking, Crop, Remove or Red Eye and the panel you came from is there again, at the same width and scroll + position, and the photo doesn't move; if the panel was hidden, it stays hidden. Pressing a panel key a second time + (I for Info, M for Masking, C for Crop, H for Remove) or its tool-strip button puts back exactly what the right + column showed before: Edit → I → I is Edit again, Masks → I → I is Masks, and a closed panel stays closed. + ## 2026-10-24 ### Relative-date filters and smart albums follow the clock From 426fc030349a81c7c810fa7b99deb928fcf16ee3 Mon Sep 17 00:00:00 2001 From: Adrian D'souza Date: Mon, 26 Oct 2026 11:07:02 +1100 Subject: [PATCH 09/57] LR-MERGE-HDRPANO: a repeated identical HDR merge reuses the verified output Running Photo Merge > HDR again on the same sources with the same options created a duplicate output. The merge now reuses the earlier output when it still matches (same sources, options and an intact file), and refuses a stale or duplicate reuse, producing a fresh merge instead. Existing edits on the output are left alone. Fixes #430. Refs #1947. Sources: own design. (cherry picked from commit 3267132d3e39672a8dc8c0905d9fd17966232fe4) (cherry picked from commit 101efb1ae0e4debe6e3cf4c232d62e24a4cde3d3) (cherry picked from commit 6459531cfb967943359d415c60a6570000c304af) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/merge.rs | 73 +++++++++++++++++++++++++------- crates/engine/src/tests_merge.rs | 70 +++++++++++++++++++++++++++--- 2 files changed, 122 insertions(+), 21 deletions(-) diff --git a/crates/engine/src/merge.rs b/crates/engine/src/merge.rs index 76bcfd7f29..8dd26533c8 100644 --- a/crates/engine/src/merge.rs +++ b/crates/engine/src/merge.rs @@ -430,29 +430,72 @@ impl Session { /// apply Auto Settings / the auto crop. Returns `{id, path, …info}`. pub fn finish_merge(&mut self, job: &MergeJob, out: MergeOutput) -> Result { let first = &job.sources.first().ok_or_else(|| EngineError::Other("nothing merged".into()))?.1; - // a new file under a free name (never replacing one), complete and synced before it appears - let path = lightcraft_catalog::safe_file::write_new_unique(&mut output_names(first, job.kind.suffix()), &out.dng) - .map_err(|e| EngineError::Other(format!("could not write the merged DNG next to {first}: {e}")))? - .to_string_lossy() - .to_string(); - let report = crate::import::import(self, std::slice::from_ref(&path), crate::import::ImportMode::Add)?; - let id = report - .imported - .first() - .copied() - .map(PhotoId) - .ok_or_else(|| EngineError::Other(format!("the merged file {path} could not be imported: {:?}", report.failed)))?; - if job.finish.stack { + let output_hash = lightcraft_preview::hash_bytes(&out.dng).to_string(); + // Import deduplicates by content. Reuse an existing merge only while its live source has + // matching bytes; stale, missing or deleted rows fail before another file is published. + let candidates: Vec<(PhotoId, String, bool)> = self + .catalog + .photos() + .filter_map(|p| { + if p.content_hash.as_deref() != Some(output_hash.as_str()) { + return None; + } + let Source::File { path } = &p.source else { return None }; + Some((p.id, path.clone(), p.deleted)) + }) + .collect(); + let valid_existing = candidates + .iter() + .find(|(_, path, deleted)| { + if *deleted { + return false; + } + let bytes = match &self.media.file_bytes { + Some(read) => read(path).ok(), + None => std::fs::read(path).ok(), + }; + bytes.is_some_and(|bytes| lightcraft_preview::hash_bytes(&bytes).to_string() == output_hash) + }) + .cloned(); + let (id, path, reused) = if let Some((id, path, _)) = valid_existing { + (id, path, true) + } else if let Some((id, path, deleted)) = candidates.first() { + let state = if *deleted { "deleted" } else { "missing or changed" }; + return Err(EngineError::Other(format!( + "existing merge result {id:?} has a {state} source at {path}; relink or remove it before repeating the merge" + ))); + } else { + // A new file under a free name (never replacing one), complete and synced before it appears. + let path = lightcraft_catalog::safe_file::write_new_unique(&mut output_names(first, job.kind.suffix()), &out.dng) + .map_err(|e| EngineError::Other(format!("could not write the merged DNG next to {first}: {e}")))? + .to_string_lossy() + .to_string(); + let report = match crate::import::import(self, std::slice::from_ref(&path), crate::import::ImportMode::Add) { + Ok(report) => report, + Err(e) => { + let _ = std::fs::remove_file(&path); + return Err(e); + } + }; + if let Some(id) = report.imported.first().copied().map(PhotoId) { + (id, path, false) + } else { + let _ = std::fs::remove_file(&path); + return Err(EngineError::Other(format!("the merged file {path} could not be imported: {:?}", report.failed))); + } + }; + if !reused && job.finish.stack { let sources: Vec = job.sources.iter().map(|(p, _)| *p).collect(); if let Some(op) = self.catalog.stack_with_ops(id, &sources) { self.commit("Stack with Sources", op)?; } } self.selection = crate::Selection::single(id); - if job.finish.auto_settings { + if !reused && job.finish.auto_settings { self.execute("develop.auto", &json!({}))?; } - if let Some(c) = out.crop + if !reused + && let Some(c) = out.crop && let Some(d) = self.develop_of(id) { let mut d = (*d).clone(); diff --git a/crates/engine/src/tests_merge.rs b/crates/engine/src/tests_merge.rs index ed524ae3d2..550a550f9d 100644 --- a/crates/engine/src/tests_merge.rs +++ b/crates/engine/src/tests_merge.rs @@ -55,15 +55,24 @@ fn hdr_merge_command_creates_and_imports_a_dng() { assert_eq!(st.photos[1..].iter().map(|p| p.0).collect::>(), ids); assert!(st.collapsed); assert_eq!(s.visible_cloned(), vec![id]); - // the second merge doesn't overwrite the first - let r2 = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": false})).unwrap(); - assert!(r2["path"].as_str().unwrap().ends_with("IMG_0-HDR-2.dng")); - let id2 = lightcraft_catalog::PhotoId(r2["id"].as_u64().unwrap()); - assert!(s.catalog.stack_of(id2).is_none(), "no stack without the option"); + // A repeated deterministic merge reuses the existing content instead of publishing an + // unimported uniquely named orphan. + s.execute("develop.set", &json!({"control": "light.exposure", "value": 0.73})).unwrap(); + let edited = s.develop_of(id).unwrap().as_ref().clone(); + let stack_before = s.catalog.stack_of(id).unwrap().clone(); + let undo_before = s.undo.len(); + let r2 = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": true, "stack": true})).unwrap(); + assert_eq!(r2["id"].as_u64(), Some(id.0)); + assert_eq!(r2["path"].as_str(), Some(path)); + assert!(!dir.join("IMG_0-HDR-2.dng").exists(), "duplicate merge left an orphan"); + assert_eq!(s.catalog.photos().count(), 4); + assert_eq!(s.undo.len(), undo_before, "reusing merge content added an undo step"); + assert_eq!(s.develop_of(id).unwrap().as_ref(), &edited, "reusing merge content changed edits"); + assert_eq!(s.catalog.stack_of(id), Some(&stack_before), "reusing merge content changed stack"); // the type filter finds merge results (and only them) s.execute("library.filter", &json!({"merged": "hdr"})).unwrap(); let found: std::collections::HashSet<_> = s.catalog.query(&s.filter, &Default::default()).into_iter().collect(); - assert_eq!(found, [id, id2].into_iter().collect()); + assert_eq!(found, [id].into_iter().collect()); let _ = std::fs::remove_dir_all(&dir); } @@ -143,6 +152,55 @@ fn a_merge_of_raws_without_colour_matrices_keeps_their_colour() { let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn hdr_merge_refuses_stale_result_before_writing() { + let dir = temp_dir("hdr-stale"); + let mut paths = Vec::new(); + for (i, b) in lightcraft_merge::synth::bracket_dngs(240, 160, &[-2.0, 0.0, 2.0]).unwrap().into_iter().enumerate() { + let p = dir.join(format!("IMG_{i}.dng")); + std::fs::write(&p, b).unwrap(); + paths.push(p.to_string_lossy().to_string()); + } + let mut s = Session::new().with_fs(); + let ids = import(&mut s, paths.clone()); + let first = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": false})).unwrap(); + let id = lightcraft_catalog::PhotoId(first["id"].as_u64().unwrap()); + let path = first["path"].as_str().unwrap().to_string(); + s.execute("develop.set", &json!({"control": "light.exposure", "value": 0.73})).unwrap(); + let edited = s.develop_of(id).unwrap().as_ref().clone(); + let stack_before = s.catalog.stack_of(id).cloned(); + + std::fs::remove_file(&path).unwrap(); + let undo_before = s.undo.len(); + let missing = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": true})); + assert!(missing.as_ref().unwrap_err().to_string().contains("missing or changed")); + assert!(!std::path::Path::new(&path).exists()); + assert!(!dir.join("IMG_0-HDR-2.dng").exists()); + assert_eq!(s.undo.len(), undo_before); + assert_eq!(s.develop_of(id).unwrap().as_ref(), &edited, "repair changed edits"); + assert_eq!(s.catalog.stack_of(id).cloned(), stack_before); + + std::fs::write(&path, std::fs::read(&paths[0]).unwrap()).unwrap(); + let changed_bytes = std::fs::read(&path).unwrap(); + let changed = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": true})); + assert!(changed.as_ref().unwrap_err().to_string().contains("missing or changed")); + assert_eq!(std::fs::read(&path).unwrap(), changed_bytes); + assert!(!dir.join("IMG_0-HDR-2.dng").exists()); + assert_eq!(s.undo.len(), undo_before); + assert_eq!(s.develop_of(id).unwrap().as_ref(), &edited, "changed-source repair changed edits"); + assert_eq!(s.catalog.stack_of(id).cloned(), stack_before); + + s.execute("photo.delete", &json!({"ids": [id.0]})).unwrap(); + let deleted_bytes = std::fs::read(&path).unwrap(); + let undo_after_delete = s.undo.len(); + let failed = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": false})); + assert!(failed.as_ref().unwrap_err().to_string().contains("deleted")); + assert_eq!(std::fs::read(&path).unwrap(), deleted_bytes); + assert!(!dir.join("IMG_0-HDR-3.dng").exists(), "failed import left an orphan"); + assert_eq!(s.undo.len(), undo_after_delete); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn panorama_command_with_auto_crop() { let dir = temp_dir("pano"); From 824395025b31afdb6d689287e5ad1137f4a0355c Mon Sep 17 00:00:00 2001 From: Andrew Frahn Date: Mon, 26 Oct 2026 11:17:48 +1100 Subject: [PATCH 10/57] security(codecs): refuse decodes with no pixels; checked JPEG sample counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `decode_unguarded` returns `Malformed` for an image of zero width or height or a buffer shorter than its size, so nothing downstream receives an empty image. - The JPEG short-output checks compute w × h × channels with `checked_sample_buf_len` instead of a `usize` product that wraps on wasm32. Refs #2579 Co-Authored-By: Claude Opus 5.5 --- crates/codecs/src/jpeg.rs | 6 ++++-- crates/codecs/src/lib.rs | 9 ++++++++- crates/codecs/tests/it/fuzz.rs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/codecs/src/jpeg.rs b/crates/codecs/src/jpeg.rs index d8b0241a13..ae9a1a61ae 100644 --- a/crates/codecs/src/jpeg.rs +++ b/crates/codecs/src/jpeg.rs @@ -226,7 +226,7 @@ fn decode_zune(bytes: &[u8], m: &Markers, budget: &DecodeOptions) -> Result let info = d.info().ok_or_else(|| Error::Malformed(F, "no info".into()))?; let (w, h) = (info.width as usize, info.height as usize); let model = if gray { Model::Gray } else { Model::Rgb }; - if px.len() < w * h * model.channels() { + if crate::checked_sample_buf_len(w, h, model.channels()).is_none_or(|n| (px.len() as u64) < n) { return Err(Error::Malformed(F, "short output".into())); } Ok(Raw { width: w, height: h, model, alpha: false, premultiplied: false, buf: Buf::U8(px), bit_depth: 8 }) @@ -403,7 +403,9 @@ pub(crate) fn decode_codes8(bytes: &[u8]) -> Result<(usize, usize, usize, Vec= raw.width * raw.height * ch => Ok((raw.width, raw.height, ch, v)), + Buf::U8(v) if crate::checked_sample_buf_len(raw.width, raw.height, ch).is_some_and(|n| v.len() as u64 >= n) => { + Ok((raw.width, raw.height, ch, v)) + } _ => Err(Error::Malformed(F, "unexpected sample format".into())), } } diff --git a/crates/codecs/src/lib.rs b/crates/codecs/src/lib.rs index a20a47d14c..f4fd1a8567 100644 --- a/crates/codecs/src/lib.rs +++ b/crates/codecs/src/lib.rs @@ -230,7 +230,7 @@ pub fn decode_unguarded(bytes: &[u8], format: Format, opts: &DecodeOptions) -> R let opts = *opts; // The reason a format can't be decoded lives in one place, `Format::not_decodable`. let unsupported = || Err(Error::Unsupported(format, format.not_decodable().unwrap_or("not decodable in this build"))); - match format { + let d = match format { Format::Jpeg => jpeg::decode(bytes, &opts), Format::Png => png_codec::decode(bytes, &opts), Format::Tiff => tiff_codec::decode(bytes, &opts), @@ -243,7 +243,14 @@ pub fn decode_unguarded(bytes: &[u8], format: Format, opts: &DecodeOptions) -> R Format::Jxl => unsupported(), Format::Heif => heif::decode(bytes, &opts), Format::Avif | Format::RawTiffLike | Format::RawOther => unsupported(), + }?; + // an image with no pixels (a malformed header claiming zero width or height, or a buffer + // shorter than its size) is refused here, so nothing downstream sees an empty image + let (w, h) = (d.image.width, d.image.height); + if w == 0 || h == 0 || w.checked_mul(h).is_none_or(|n| d.image.data.len() < n) { + return Err(Error::Malformed(format, "image has no pixels".into())); } + Ok(d) } /// Convert a decode result to linear Rec.2020 D65 (Bradford-adapted), the develop working space. diff --git a/crates/codecs/tests/it/fuzz.rs b/crates/codecs/tests/it/fuzz.rs index bfee84dfe4..d79bd7bd36 100644 --- a/crates/codecs/tests/it/fuzz.rs +++ b/crates/codecs/tests/it/fuzz.rs @@ -85,6 +85,22 @@ fn thumbnail_respects_configured_source_pixel_limit() { assert_eq!(decode_thumbnail_with(&bytes, &opts).unwrap().image.width, 1); } +/// A header claiming zero width or height is an error, never a decoded image with no pixels +/// (downstream filters index into it). +#[test] +fn zero_size_headers_are_refused() { + let jpeg = seeds()[0].clone(); + let sof = jpeg.windows(2).position(|m| m == [0xFF, 0xC0]).unwrap(); + for at in [sof + 5, sof + 7] { + let mut j = jpeg.clone(); + j[at..at + 2].copy_from_slice(&[0, 0]); + assert!(decode_unguarded(&j, Format::Jpeg, &small_opts()).is_err()); + } + let mut png = seeds()[1].clone(); + png[16..20].copy_from_slice(&[0; 4]); + assert!(decode_unguarded(&png, Format::Png, &small_opts()).is_err()); +} + fn seeds() -> &'static Vec> { static S: OnceLock>> = OnceLock::new(); S.get_or_init(|| { From 9d09ba4941c6431c5b2ed09aebc2c6545b310f0f Mon Sep 17 00:00:00 2001 From: Andrew Frahn Date: Mon, 26 Oct 2026 11:47:06 +1100 Subject: [PATCH 11/57] LR-MERGE-HDRPANO: the merge result reports whether it reused an earlier output CLI, MCP and control-channel callers can now tell a reused result (edits kept, autoSettings/stack/auto-crop skipped) from a fresh merge. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/merge.rs | 1 + crates/engine/src/tests_merge.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/crates/engine/src/merge.rs b/crates/engine/src/merge.rs index 8dd26533c8..70ad1328fb 100644 --- a/crates/engine/src/merge.rs +++ b/crates/engine/src/merge.rs @@ -506,6 +506,7 @@ impl Session { info["id"] = json!(id.0); info["path"] = json!(path); info["bytes"] = json!(out.dng.len()); + info["reused"] = json!(reused); Ok(info) } diff --git a/crates/engine/src/tests_merge.rs b/crates/engine/src/tests_merge.rs index 550a550f9d..7c30379ed7 100644 --- a/crates/engine/src/tests_merge.rs +++ b/crates/engine/src/tests_merge.rs @@ -40,6 +40,7 @@ fn hdr_merge_command_creates_and_imports_a_dng() { let r = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": true, "stack": true})).unwrap(); let path = r["path"].as_str().unwrap(); assert!(path.ends_with("IMG_0-HDR.dng"), "{path}"); + assert_eq!(r["reused"].as_bool(), Some(false)); let id = lightcraft_catalog::PhotoId(r["id"].as_u64().unwrap()); let p = s.catalog.photo(id).unwrap().clone(); assert_eq!((p.width, p.height), (480, 320)); @@ -63,6 +64,7 @@ fn hdr_merge_command_creates_and_imports_a_dng() { let undo_before = s.undo.len(); let r2 = s.execute("merge.hdr", &json!({"ids": ids, "autoSettings": true, "stack": true})).unwrap(); assert_eq!(r2["id"].as_u64(), Some(id.0)); + assert_eq!(r2["reused"].as_bool(), Some(true)); assert_eq!(r2["path"].as_str(), Some(path)); assert!(!dir.join("IMG_0-HDR-2.dng").exists(), "duplicate merge left an orphan"); assert_eq!(s.catalog.photos().count(), 4); From 0f17c6f3eb5f63f7a3a1261fca33168ddb08a6d5 Mon Sep 17 00:00:00 2001 From: OneSlips Date: Mon, 26 Oct 2026 15:11:41 +1000 Subject: [PATCH 12/57] KEY-INFO: main's docking test expects Crop toggled off to give back the panel it replaced Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tests_docking_acceptance.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tests_docking_acceptance.rs b/crates/ui-egui/src/tests_docking_acceptance.rs index 207ad5fae8..e0c274e45e 100644 --- a/crates/ui-egui/src/tests_docking_acceptance.rs +++ b/crates/ui-egui/src/tests_docking_acceptance.rs @@ -185,6 +185,7 @@ fn dock_tab_keeps_activation_keys_and_global_command_remains_reachable() { let mut h = app(); h.app.run("app.setShortcut", json!({"id":"panel.crop","shortcut":"K"})).unwrap(); dock(&mut h, json!({"operation":"move","panel":"tools","target":"library","zone":"center"})); + let before = h.app.ui.right; h.app.run("panel.crop", json!({})).unwrap(); h.step(); // The test chooses the renderer's actual registered tab, rather than an arbitrary focus owner. @@ -194,7 +195,9 @@ fn dock_tab_keeps_activation_keys_and_global_command_remains_reachable() { key(&mut h, egui::Key::Enter); assert_eq!(h.app.ui.right, RightPanel::Crop, "Enter activates the tab without tool.done"); key(&mut h, egui::Key::K); - assert_eq!(h.app.ui.right, RightPanel::None, "the global crop toggle is reachable from tab focus"); + // toggled off, Crop gives back the panel it took the place of (KEY-INFO / UiState::toggle_panel) + assert_eq!(h.app.ui.right, before, "the global crop toggle is reachable from tab focus"); + assert_ne!(before, RightPanel::Crop); } #[test] From a016dca0b540237f92d751c373236c4f6510392d Mon Sep 17 00:00:00 2001 From: OneSlips Date: Mon, 26 Oct 2026 15:35:16 +1000 Subject: [PATCH 13/57] KEY-INFO: a ui.set between the two presses keeps the pending panel toggle (CodeRabbit, #3031) ui.set copied tool_return and right_seen into the new UiState but not toggle_return, so Edit -> I -> ui.set -> I closed the column. Also a test that a tool panel restored from saved state closes to Edit. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/control.rs | 2 ++ crates/ui-egui/src/tests_panel_restore.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 5e43b1477a..030c4be1c8 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -403,6 +403,8 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest // the panel a tool panel took the place of, to put back when it closes, survives a ui.set u.tool_return = app.ui.tool_return; u.right_seen = app.ui.right_seen; + // (and what a panel toggle replaced, so pressing its key again still puts that back) + u.toggle_return = app.ui.toggle_return; u.dialog = app.ui.dialog.clone(); u.status = app.ui.status.clone(); crate::docking::cancel_replaced_gesture(app, u.docking.as_ref()); diff --git a/crates/ui-egui/src/tests_panel_restore.rs b/crates/ui-egui/src/tests_panel_restore.rs index 640428a6c9..a90663ea87 100644 --- a/crates/ui-egui/src/tests_panel_restore.rs +++ b/crates/ui-egui/src/tests_panel_restore.rs @@ -143,3 +143,26 @@ fn info_toggled_off_brings_back_exactly_what_was_there() { key(&mut h); assert_eq!(h.app.ui.right, RightPanel::None, "closed → I → I = closed"); } + +/// A `ui.set` that changes something else (here the panel width) keeps a pending toggle: I still puts Edit back +/// (CodeRabbit on #3031). +#[test] +fn a_ui_set_between_the_two_presses_keeps_the_toggle() { + let mut h = detail(); + exec(&mut h, "panel.info"); + assert_eq!(h.app.ui.right, RightPanel::Info); + let r = h.request("ui.set", json!({"rightWidth": 320.0}), T); + assert_eq!(r["ok"], true, "{r}"); + h.step(); + exec(&mut h, "panel.info"); + assert_eq!(h.app.ui.right, RightPanel::Edit, "Edit → I → ui.set → I = Edit"); +} + +/// A tool panel restored from the saved UI state (the panel before it unknown) closes to Edit, not to a hidden column. +#[test] +fn a_tool_restored_from_saved_state_closes_to_edit() { + let mut ui: crate::state::UiState = serde_json::from_str(r#"{"right": "crop"}"#).unwrap(); + assert_eq!(ui.right, RightPanel::Crop); + ui.note_right(); + assert_eq!(ui.leave_tool(), RightPanel::Edit); +} From a9afb1868c069257741214c35776b77464074d67 Mon Sep 17 00:00:00 2001 From: Andrew Frahn Date: Tue, 27 Oct 2026 17:31:27 +1100 Subject: [PATCH 14/57] test(codecs): test the no-pixels guard and checked JPEG sample count directly Moves the final-output check into check_has_pixels and tests it with zero width, zero height, an overflowing w*h and a short RGB buffer (fails when the guard is removed). Adds the 65535x21846x3 case a 32-bit usize product wraps. The PNG zero-dimension fixture now repairs its IHDR CRC and covers height too. Co-Authored-By: Claude Opus 5.5 --- crates/codecs/src/lib.rs | 41 +++++++++++++++++++++++++++++----- crates/codecs/tests/it/fuzz.rs | 27 +++++++++++++++++++--- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/crates/codecs/src/lib.rs b/crates/codecs/src/lib.rs index f4fd1a8567..07d895a985 100644 --- a/crates/codecs/src/lib.rs +++ b/crates/codecs/src/lib.rs @@ -244,13 +244,19 @@ pub fn decode_unguarded(bytes: &[u8], format: Format, opts: &DecodeOptions) -> R Format::Heif => heif::decode(bytes, &opts), Format::Avif | Format::RawTiffLike | Format::RawOther => unsupported(), }?; - // an image with no pixels (a malformed header claiming zero width or height, or a buffer - // shorter than its size) is refused here, so nothing downstream sees an empty image - let (w, h) = (d.image.width, d.image.height); - if w == 0 || h == 0 || w.checked_mul(h).is_none_or(|n| d.image.data.len() < n) { + check_has_pixels(format, &d.image)?; + Ok(d) +} + +/// An image with no pixels (a malformed header claiming zero width or height, a `w × h` that +/// overflows, or a buffer shorter than its size) is refused, so nothing downstream sees an empty +/// image. +fn check_has_pixels(format: Format, image: &Rgb32f) -> Result<()> { + let (w, h) = (image.width, image.height); + if w == 0 || h == 0 || w.checked_mul(h).is_none_or(|n| image.data.len() < n) { return Err(Error::Malformed(format, "image has no pixels".into())); } - Ok(d) + Ok(()) } /// Convert a decode result to linear Rec.2020 D65 (Bradford-adapted), the develop working space. @@ -370,4 +376,29 @@ mod checked_arithmetic_tests { // 300 Mpx RGBA is within the default pixel limit, so it must not be refused by sample count. assert_eq!(checked_sample_buf_len(20_000, 15_000, 4), Some(1_200_000_000)); } + + #[test] + fn checked_sample_buf_len_does_not_wrap_like_32_bit_usize() { + // 65535 × 21846 × 3 = 4_295_032_830, which a 32-bit `usize` product wraps to 65_534 + assert_eq!(checked_sample_buf_len(65_535, 21_846, 3), Some(4_295_032_830)); + assert!(checked_sample_buf_len(65_535, 21_846, 3).is_some_and(|n| n > 65_534)); + } + + fn image(width: usize, height: usize, len: usize) -> Rgb32f { + Rgb32f { width, height, data: vec![[0.0; 3]; len] } + } + + #[test] + fn decoded_image_without_pixels_is_refused() { + for (w, h, len) in [(0, 4, 0), (4, 0, 0), (usize::MAX, 2, 1), (4, 4, 15)] { + let r = check_has_pixels(Format::Png, &image(w, h, len)); + assert!(matches!(r, Err(Error::Malformed(Format::Png, _))), "{w}x{h} with {len} pixels"); + } + } + + #[test] + fn decoded_image_with_all_pixels_is_accepted() { + assert!(check_has_pixels(Format::Png, &image(4, 4, 16)).is_ok()); + assert!(check_has_pixels(Format::Png, &image(1, 1, 1)).is_ok()); + } } diff --git a/crates/codecs/tests/it/fuzz.rs b/crates/codecs/tests/it/fuzz.rs index d79bd7bd36..0fa56101eb 100644 --- a/crates/codecs/tests/it/fuzz.rs +++ b/crates/codecs/tests/it/fuzz.rs @@ -88,6 +88,9 @@ fn thumbnail_respects_configured_source_pixel_limit() { /// A header claiming zero width or height is an error, never a decoded image with no pixels /// (downstream filters index into it). #[test] +// End-to-end no-panic check: headers claiming a zero dimension are errors. The JPEG and PNG +// readers already refuse these; `decode_unguarded`'s own final-output guard is tested directly in +// the crate's unit tests. fn zero_size_headers_are_refused() { let jpeg = seeds()[0].clone(); let sof = jpeg.windows(2).position(|m| m == [0xFF, 0xC0]).unwrap(); @@ -96,9 +99,27 @@ fn zero_size_headers_are_refused() { j[at..at + 2].copy_from_slice(&[0, 0]); assert!(decode_unguarded(&j, Format::Jpeg, &small_opts()).is_err()); } - let mut png = seeds()[1].clone(); - png[16..20].copy_from_slice(&[0; 4]); - assert!(decode_unguarded(&png, Format::Png, &small_opts()).is_err()); + let png = seeds()[1].clone(); + for at in [16, 20] { + let mut p = png.clone(); + p[at..at + 4].copy_from_slice(&[0; 4]); + // repair the IHDR CRC so the dimension, not the checksum, is what gets refused + let crc = crc32(&p[12..29]); + p[29..33].copy_from_slice(&crc.to_be_bytes()); + assert!(decode_unguarded(&p, Format::Png, &small_opts()).is_err()); + } +} + +/// CRC-32 (IEEE), as PNG chunks use. +fn crc32(bytes: &[u8]) -> u32 { + let mut c = !0u32; + for &b in bytes { + c ^= u32::from(b); + for _ in 0..8 { + c = if c & 1 != 0 { 0xEDB8_8320 ^ (c >> 1) } else { c >> 1 }; + } + } + !c } fn seeds() -> &'static Vec> { From 4371ac5860376405e450e38ed7f2888251ab4529 Mon Sep 17 00:00:00 2001 From: OneSlips Date: Wed, 28 Oct 2026 07:17:18 +1000 Subject: [PATCH 15/57] KEY-INFO: the Keywords panel scrolls under one id with or without a selection; KEY-COMMIT row says where Return goes Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/menus/run.rs | 2 +- crates/ui-egui/src/panels/right.rs | 10 ++++++++-- crates/ui-egui/src/panels/right/tests.rs | 11 +++++++++++ docs/parity-checklist.md | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index df3816449f..0b734be463 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -1021,7 +1021,7 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option { - // Return commits a tool panel (crop, remove, red eye, masking): back to Edit + // Return commits a tool panel (crop, remove, red eye, masking): back to the panel before it use RightPanel::*; if app.ui.dialog.is_none() && matches!(app.ui.right, Crop | Remove | RedEye | Masking) { let _ = app.session.end_interaction(); diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rs index 4fee12e4f6..1b2f5266f1 100644 --- a/crates/ui-egui/src/panels/right.rs +++ b/crates/ui-egui/src/panels/right.rs @@ -28,6 +28,12 @@ use info::info; pub(crate) use info::mixed_meta; use keywords::keywords; +/// The right column's scroll area for `panel`: one per panel, the same with or without a selected photo (the +/// Keywords panel shows its list either way). +fn scroll_salt(panel: RightPanel) -> (&'static str, RightPanel) { + ("right-scroll", panel) +} + pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { let t = Tokens::get(ui.ctx()); let frame = egui::Frame::NONE.fill(t.chrome).stroke(egui::Stroke::new(1.0, t.divider)); @@ -39,7 +45,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { if app.ui.right == RightPanel::Keywords { // (without a selection there is no Add keyword box for Add Keywords to put the cursor in) app.ui.focus_keywords = None; - egui::ScrollArea::vertical().id_salt("right-scroll").auto_shrink([false, false]).show(ui, |ui| { + egui::ScrollArea::vertical().id_salt(scroll_salt(RightPanel::Keywords)).auto_shrink([false, false]).show(ui, |ui| { ui.spacing_mut().item_spacing.y = 0.0; if fold_header(app, ui, "keywording", "Keywords") { padded(ui, |ui| { @@ -60,7 +66,7 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui) { return; }; // each panel keeps its own scroll position: Edit is where it was after Masking or Crop - let mut area = egui::ScrollArea::vertical().id_salt(("right-scroll", app.ui.right)).auto_shrink([false, false]); + let mut area = egui::ScrollArea::vertical().id_salt(scroll_salt(app.ui.right)).auto_shrink([false, false]); if let Some(offset) = held { area = area.vertical_scroll_offset(offset); } diff --git a/crates/ui-egui/src/panels/right/tests.rs b/crates/ui-egui/src/panels/right/tests.rs index 1f1d60d609..482cdfceb0 100644 --- a/crates/ui-egui/src/panels/right/tests.rs +++ b/crates/ui-egui/src/panels/right/tests.rs @@ -30,3 +30,14 @@ fn short_times() { assert_eq!(super::short_time("2026-09-30T12:00:05"), "Sep 30, 2026, 12:00 PM"); assert_eq!(super::short_time("2026-01-02"), "Jan 2, 2026"); } + +// Feature: the Keywords panel keeps its scroll position when a photo is selected (CodeRabbit on #3031: the +// no-selection list scrolled under another id) +#[test] +fn the_keywords_panel_scrolls_under_one_id_with_or_without_a_selection() { + use crate::state::RightPanel; + // (`show` names the no-selection list's scroll area by `scroll_salt(RightPanel::Keywords)`, as it names the + // panel's with a selection by `scroll_salt(app.ui.right)`) + assert_eq!(super::scroll_salt(RightPanel::Keywords), ("right-scroll", RightPanel::Keywords)); + assert_ne!(super::scroll_salt(RightPanel::Keywords), super::scroll_salt(RightPanel::Edit), "each panel keeps its own"); +} diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index 288d9213f7..c0d196b3f1 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -681,7 +681,7 @@ From `06-shortcuts.md` part 1. Evidence is our binding; conflicts are explained | KEY-HELP | Help — F1 | P2 | ✅ | `cmd:app.help` | | | KEY-VIDEO-PLAY | Play/pause video — Space | P1 | ⬜ | | | | KEY-ESC | Leave tool / view — Esc | P0 | ✅ | `cmd:view.back`, `crates/ui-egui/src/icons.rs` (`navigation_arrowheads_have_both_halves`), `crates/ui-egui/src/tests/crop_tool.rs` | top-bar navigation arrowheads render both halves at 1× and 2× scale; in the crop tool Esc closes the tool first (the crop stays), the next Esc goes back to the grid; Esc that ends an edit in a text field does nothing else | -| KEY-COMMIT | Commit tool — Return | P1 | ✅ | `cmd:tool.done` | Return closes Crop / Remove / Red Eye / Masking back to Edit (edits apply live, as in Lightroom) | +| KEY-COMMIT | Commit tool — Return | P1 | ✅ | `cmd:tool.done` | Return closes Crop / Remove / Red Eye / Masking and goes back to the panel shown before the tool, the right column hidden again if it was (edits apply live, as in Lightroom) | | KEY-DELETE-PIN | Delete selected pin — ⌫ | P0 | ✅ | `cmd:mask.delete`, `cmd:spot.delete` | ⌫ deletes the active mask (Masking) or the selected spot (Remove), never the photo while retouching | | KEY-HIDEPINS | Hide pins — H | P2 | ✅ | `cmd:view.toolOverlay`, `crates/ui-egui/src/tests/tool_overlay.rs` | ⇧H cycles the Tool Overlay (Auto → Always → Selected → Never) for spot and mask pins, since H opens Remove; also View ▸ Tool Overlay and the Remove / Masking panels (#224) | From ef01264ca77a91ec3033407323949ab3a96e5cda Mon Sep 17 00:00:00 2001 From: OneSlips Date: Wed, 28 Oct 2026 08:39:14 +1000 Subject: [PATCH 16/57] KEY-INFO: the panel-restore test covers Red Eye too Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tests/panel_restore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tests/panel_restore.rs b/crates/ui-egui/src/tests/panel_restore.rs index a90663ea87..1793e09529 100644 --- a/crates/ui-egui/src/tests/panel_restore.rs +++ b/crates/ui-egui/src/tests/panel_restore.rs @@ -59,7 +59,7 @@ fn the_edit_panel_comes_back_after_masking_and_crop_where_it_was() { } let (slider, at) = first_slider(&h); let photo = widget(&h, "canvas:image").expect("the photo"); - for tool in ["panel.masking", "panel.crop", "panel.remove"] { + for tool in ["panel.masking", "panel.crop", "panel.remove", "panel.redeye"] { exec(&mut h, tool); assert!(h.app.ui.right.is_tool(), "{tool}: {:?}", h.app.ui.right); assert_eq!(widget(&h, "panel:right_panel"), Some(panel), "{tool}: the panel keeps its place and width"); From 0b9343904ee85319e961a609c9a40fc167105ae7 Mon Sep 17 00:00:00 2001 From: OneSlips Date: Wed, 28 Oct 2026 10:36:15 +1000 Subject: [PATCH 17/57] KEY-INFO: a tool F8 hid and showed again still closes to the panel before it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Info → Crop → F8 → F8 → Done went to a hidden column: F8's hidden column cleared the tool's return panel and the restored tool recorded the hidden column instead. note_right keeps the return panel while F8 hides the tool on show and doesn't overwrite it when F8 shows it again (CodeRabbit on #3031). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/state.rs | 8 +++++-- crates/ui-egui/src/tests/panel_restore.rs | 28 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 67d70746bd..3db12c0cd5 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -377,10 +377,14 @@ impl UiState { self.toggle_return = None; } if self.right.is_tool() { - if !self.right_seen.is_tool() { + // F8 showing a tool it hid: the panel before that tool still holds (`None` is F8's hidden column, not + // what the tool came from) + let back_from_f8 = self.right_seen == RightPanel::None && self.tool_return.is_some(); + if !self.right_seen.is_tool() && !back_from_f8 { self.tool_return = Some(self.right_seen); } - } else { + } else if !(self.right == RightPanel::None && self.right_seen.is_tool() && self.right_hidden == self.right_seen) { + // any panel but F8 hiding the tool on show forgets it self.tool_return = None; } self.right_seen = self.right; diff --git a/crates/ui-egui/src/tests/panel_restore.rs b/crates/ui-egui/src/tests/panel_restore.rs index 1793e09529..9b6bd89c6d 100644 --- a/crates/ui-egui/src/tests/panel_restore.rs +++ b/crates/ui-egui/src/tests/panel_restore.rs @@ -166,3 +166,31 @@ fn a_tool_restored_from_saved_state_closes_to_edit() { ui.note_right(); assert_eq!(ui.leave_tool(), RightPanel::Edit); } + +/// F8 hiding a tool and F8 showing it again keeps what the tool closes to: Info → Crop → F8 → F8 → Done = Info, not a +/// hidden column (CodeRabbit on #3031). +#[test] +fn a_tool_hidden_and_shown_by_f8_still_closes_to_the_panel_before_it() { + let mut h = detail(); + for close in ["tool.done", "panel.crop"] { + exec(&mut h, "panel.close"); + exec(&mut h, "panel.info"); + assert_eq!(h.app.ui.right, RightPanel::Info); + exec(&mut h, "panel.crop"); + assert_eq!(h.app.ui.right, RightPanel::Crop); + exec(&mut h, "view.rightPanel"); + assert_eq!(h.app.ui.right, RightPanel::None, "F8 hides Crop"); + exec(&mut h, "view.rightPanel"); + assert_eq!(h.app.ui.right, RightPanel::Crop, "F8 shows Crop again"); + exec(&mut h, close); + assert_eq!(h.app.ui.right, RightPanel::Info, "{close}: Info → Crop → F8 → F8 → closed = Info"); + } + // a panel picked while the tool was hidden is not undone: Crop → F8 → Masking → closed = closed, as before + exec(&mut h, "panel.close"); + exec(&mut h, "panel.crop"); + exec(&mut h, "view.rightPanel"); + exec(&mut h, "panel.info"); + exec(&mut h, "panel.masking"); + exec(&mut h, "panel.masking"); + assert_eq!(h.app.ui.right, RightPanel::Info, "a panel picked after F8 is what comes back"); +} From 04f46cf1c951d7b8201d0af359315096ab7ca701 Mon Sep 17 00:00:00 2001 From: OneSlips Date: Wed, 28 Oct 2026 12:37:24 +1000 Subject: [PATCH 18/57] KEY-INFO: F8 keeps a tool's way back; nested panel toggles unwind one at a time (CodeRabbit, #3031) - A tool opened on the column F8 hid (Info, Crop, F8, Brush, Done) closes to the hidden column: only a tool F8 itself shows again keeps the panel it came from (an explicit `right_shown_by_f8`, consumed by `note_right`). - F8 hiding and showing a panel a toggle opened keeps its toggle record: Masking, Crop, F8, F8, Done = Masking. - Toggle records are a stack (at most 16): Edit, I, K, K, I = Edit. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/control.rs | 3 +- crates/ui-egui/src/menus/run.rs | 2 + crates/ui-egui/src/state.rs | 44 ++++++++++++----- crates/ui-egui/src/tests/panel_restore.rs | 57 +++++++++++++++++++++++ 4 files changed, 93 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 030c4be1c8..481fad16a3 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -404,7 +404,8 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context, req: &ControlRequest u.tool_return = app.ui.tool_return; u.right_seen = app.ui.right_seen; // (and what a panel toggle replaced, so pressing its key again still puts that back) - u.toggle_return = app.ui.toggle_return; + u.toggle_return = app.ui.toggle_return.clone(); + u.right_shown_by_f8 = app.ui.right_shown_by_f8; u.dialog = app.ui.dialog.clone(); u.status = app.ui.status.clone(); crate::docking::cancel_replaced_gesture(app, u.docking.as_ref()); diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index 0b734be463..8c24c70734 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -613,6 +613,8 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option p, }; app.ui.right = p; + // (a tool shown again this way still closes to the panel before it) + app.ui.right_shown_by_f8 = Some(p); if p.is_edit_tool() && !matches!(app.ui.view, ViewMode::Detail) { app.ui.view = ViewMode::Detail; } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 3db12c0cd5..81b46c3247 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -50,15 +50,21 @@ pub struct UiState { /// The right panel F8 (`view.rightPanel`) hid, which the next F8 shows again. #[serde(skip)] pub right_hidden: RightPanel, + /// The panel F8 just showed again, until [`UiState::note_right`] sees it: a tool coming back this way still closes + /// to the panel before it, while a tool opened any other way on a hidden column closes to the hidden column. + #[serde(skip)] + pub right_shown_by_f8: Option, /// The panel on show before a tool panel ([`RightPanel::is_tool`]) took its place, put back /// when the tool closes ([`RightPanel::None`]: the panel was hidden, and stays hidden). #[serde(skip)] pub tool_return: Option, - /// The panel a toggle (a panel key or button: I, M, R, Q…) opened, with what the right column showed before it - /// and that one's [`UiState::tool_return`]: toggling it off puts back exactly that, closed included (test notes - /// 2026-10-24 note 21). Forgotten once another panel is shown. + /// The panels toggles (a panel key or button: I, M, R, Q…) opened, each with what the right column showed before + /// it and that one's [`UiState::tool_return`], the latest last: toggling the panel on show off puts back exactly + /// that, closed included (test notes 2026-10-24 note 21), and the one below it is then on show with its own + /// record (Edit → I → K → K → I = Edit). Forgotten once another panel is shown (not when F8 hides the panel and + /// shows it again). At most [`TOGGLE_HISTORY`] deep. #[serde(skip)] - pub toggle_return: Option<(RightPanel, RightPanel, Option)>, + pub toggle_return: Vec<(RightPanel, RightPanel, Option)>, /// The panel [`UiState::note_right`] last saw. #[serde(skip)] pub right_seen: RightPanel, @@ -366,20 +372,26 @@ pub struct UiState { pub print: crate::print_view::PrintUi, } +/// How many panel toggles [`UiState::toggle_return`] remembers (pressing I and K in turn would grow it without end). +pub const TOGGLE_HISTORY: usize = 16; + impl UiState { /// Notes the panel on show: a tool panel opened from another panel (or from none) remembers /// that one, to put it back when the tool closes; any other panel forgets it. pub fn note_right(&mut self) { + let shown_by_f8 = self.right_shown_by_f8.take(); if self.right == self.right_seen { return; } - if self.toggle_return.is_some_and(|(opened, ..)| opened != self.right) { - self.toggle_return = None; + // F8 hiding the panel a toggle opened keeps its record, for F8 showing it again + let f8_hid = |opened: RightPanel| self.right == RightPanel::None && self.right_hidden == opened; + if self.toggle_return.last().is_some_and(|&(opened, ..)| opened != self.right && !f8_hid(opened)) { + self.toggle_return.clear(); } if self.right.is_tool() { // F8 showing a tool it hid: the panel before that tool still holds (`None` is F8's hidden column, not - // what the tool came from) - let back_from_f8 = self.right_seen == RightPanel::None && self.tool_return.is_some(); + // what the tool came from). A tool opened another way on the hidden column came from the hidden column. + let back_from_f8 = self.right_seen == RightPanel::None && shown_by_f8 == Some(self.right); if !self.right_seen.is_tool() && !back_from_f8 { self.tool_return = Some(self.right_seen); } @@ -417,9 +429,13 @@ impl UiState { false } else { let saved = (p, if exposed || self.right != p { self.right } else { RightPanel::None }, self.tool_return); + if self.toggle_return.len() >= TOGGLE_HISTORY { + self.toggle_return.remove(0); + } + // (on the history before `note_right` sees `p`: the panel it replaced keeps its own record below it) + self.toggle_return.push(saved); self.right = p; self.note_right(); - self.toggle_return = Some(saved); true } } @@ -427,8 +443,11 @@ impl UiState { /// What the toggle that opened the panel on show replaced (see [`UiState::toggle_panel`]), with its own tool /// memory put back, or `None` when that panel wasn't opened by a toggle. fn untoggle(&mut self) -> Option { - let (_, before, tool_return) = self.toggle_return.filter(|(opened, ..)| *opened == self.right)?; - self.toggle_return = None; + let &(opened, before, tool_return) = self.toggle_return.last()?; + if opened != self.right { + return None; + } + self.toggle_return.pop(); self.tool_return = tool_return; // seen already: `note_right` must not take the panel being left for the one this came back from self.right_seen = before; @@ -454,7 +473,8 @@ impl Default for UiState { right: RightPanel::Edit, right_hidden: RightPanel::None, tool_return: None, - toggle_return: None, + toggle_return: Vec::new(), + right_shown_by_f8: None, right_seen: RightPanel::Edit, presets: false, preset_thumbs: false, diff --git a/crates/ui-egui/src/tests/panel_restore.rs b/crates/ui-egui/src/tests/panel_restore.rs index 9b6bd89c6d..678853f4db 100644 --- a/crates/ui-egui/src/tests/panel_restore.rs +++ b/crates/ui-egui/src/tests/panel_restore.rs @@ -194,3 +194,60 @@ fn a_tool_hidden_and_shown_by_f8_still_closes_to_the_panel_before_it() { exec(&mut h, "panel.masking"); assert_eq!(h.app.ui.right, RightPanel::Info, "a panel picked after F8 is what comes back"); } + +/// A tool opened another way on the column F8 hid is not F8 showing a tool again: Info → Crop → F8 → Brush → Done +/// leaves the column hidden, as it was when the brush was picked (CodeRabbit on #3031). +#[test] +fn a_tool_opened_on_the_column_f8_hid_closes_to_the_hidden_column() { + let mut h = detail(); + exec(&mut h, "panel.close"); + exec(&mut h, "panel.info"); + exec(&mut h, "panel.crop"); + exec(&mut h, "view.rightPanel"); + assert_eq!(h.app.ui.right, RightPanel::None, "F8 hides Crop"); + exec(&mut h, "tool.brush"); + assert_eq!(h.app.ui.right, RightPanel::Masking); + exec(&mut h, "tool.done"); + assert_eq!(h.app.ui.right, RightPanel::None, "Info → Crop → F8 → Brush → Done = hidden"); +} + +/// A tool opened from another tool keeps where it closes to across F8: Masking → Crop → F8 → F8 → closed = Masking, +/// and Masking then closes to Edit (CodeRabbit on #3031). +#[test] +fn a_nested_tool_hidden_and_shown_by_f8_still_closes_to_the_tool_before_it() { + let mut h = detail(); + for close in ["tool.done", "panel.crop"] { + exec(&mut h, "panel.masking"); + exec(&mut h, "panel.crop"); + assert_eq!(h.app.ui.right, RightPanel::Crop); + exec(&mut h, "view.rightPanel"); + assert_eq!(h.app.ui.right, RightPanel::None, "F8 hides Crop"); + exec(&mut h, "view.rightPanel"); + assert_eq!(h.app.ui.right, RightPanel::Crop, "F8 shows Crop again"); + exec(&mut h, close); + assert_eq!(h.app.ui.right, RightPanel::Masking, "{close}: Masking → Crop → F8 → F8 → closed = Masking"); + exec(&mut h, "panel.masking"); + assert_eq!(h.app.ui.right, RightPanel::Edit, "{close}: then Masking closes to Edit"); + } +} + +/// Toggles nest: Edit → I → K → K → I = Edit, each press taking back exactly the one before it (CodeRabbit on #3031). +#[test] +fn nested_panel_toggles_come_back_one_at_a_time() { + let mut h = detail(); + exec(&mut h, "panel.info"); + exec(&mut h, "panel.keywords"); + assert_eq!(h.app.ui.right, RightPanel::Keywords); + exec(&mut h, "panel.keywords"); + assert_eq!(h.app.ui.right, RightPanel::Info, "Keywords toggled off: Info again"); + exec(&mut h, "panel.info"); + assert_eq!(h.app.ui.right, RightPanel::Edit, "Info toggled off: Edit again"); + // pressing two keys in turn many times keeps a bounded history and still unwinds to a panel + for _ in 0..crate::state::TOGGLE_HISTORY { + exec(&mut h, "panel.info"); + exec(&mut h, "panel.keywords"); + } + assert!(h.app.ui.toggle_return.len() <= crate::state::TOGGLE_HISTORY); + exec(&mut h, "panel.keywords"); + assert_eq!(h.app.ui.right, RightPanel::Info); +} From 40f10cc1c0295e9b727154532c74e6fd0a18c82e Mon Sep 17 00:00:00 2001 From: OneSlips Date: Wed, 28 Oct 2026 14:42:10 +1000 Subject: [PATCH 19/57] KEY-INFO: a tool opened from another closes back to it; F8 is noted before the next command (CodeRabbit, #3031) - A tool opened by a command rather than a toggle (B from Crop) is recorded like a toggle: Info, Crop, B, Done = Crop; Crop closed = Info; I = Edit. The records below it are kept. - F8 notes the panel change at once, so a command run in the same frame (a batch of control requests) opens a tool on the hidden column: Info, Crop, F8, Brush, Done = hidden. - The Keywords panel test scrolls the list with no photo selected and checks that the panel's scroll area keeps that offset when a photo is selected. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/menus/run.rs | 6 ++- crates/ui-egui/src/panels/right/tests.rs | 47 +++++++++++++++++++++++ crates/ui-egui/src/state.rs | 18 +++++++-- crates/ui-egui/src/tests/panel_restore.rs | 33 ++++++++++++++++ 4 files changed, 99 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rs index 8c24c70734..eb6be04fee 100644 --- a/crates/ui-egui/src/menus/run.rs +++ b/crates/ui-egui/src/menus/run.rs @@ -603,6 +603,9 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option