LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LRC-LIB-REFVIEW: refuse malformed and deleted references clearly; release a dead pane
Haocheng Fangbb5d68978b0e
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex d1ada6b23..719bcb5d6 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -587,12 +587,15 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<Re"view.reference" => {// the reference: the one set before, else the active photo (the next one becomes active)let vis = app.session.visible_cloned();- let reference = app- .ui- .reference- .filter(|r| app.session.catalog.photo(lightcraft_catalog::PhotoId(*r)).is_some_and(|p| !p.deleted))- .or_else(|| app.session.active().filter(|a| app.session.catalog.photo(*a).is_some_and(|p| !p.deleted)).map(|a| a.0));- let Some(r) = reference else { return Some(Err("select a photo to use as the reference".into())) };+ let live = |id: u64| crate::panels::compare::live(app, lightcraft_catalog::PhotoId(id));+ let active = app.session.active().map(|a| a.0);+ let reference = app.ui.reference.filter(|r| live(*r)).or_else(|| active.filter(|a| live(*a)));+ let Some(r) = reference else {+ return Some(Err(match active {+ Some(a) => format!("photo {a} is in Recently Deleted: restore it to use it as the reference"),+ None => "select a photo to use as the reference".into(),+ }));+ };app.ui.reference = Some(r);if app.session.active().is_none_or(|a| a.0 == r)&& let Some(i) = vis.iter().position(|x| x.0 == r)@@ -604,10 +607,19 @@ pub fn run_ui_command(app: &mut LightcraftApp, id: &str, p: &Value) -> Option<ReOk(json!({"reference": r, "active": app.session.active().map(|a| a.0)}))}"photo.setReference" => {- let id = p.get("id").and_then(Value::as_u64).or_else(|| app.session.active().map(|a| a.0));+ // only an absent (or null) `id` means the active photo; any other non-id is refused+ let id = match p.get("id").filter(|v| !v.is_null()) {+ Some(v) => match v.as_u64() {+ Some(id) => Some(id),+ None => return Some(Err(format!("photo.setReference: `id` must be a photo id, not {v}"))),+ },+ None => app.session.active().map(|a| a.0),+ };let Some(id) = id else { return Some(Err("select a photo to use as the reference".into())) };- if app.session.catalog.photo(lightcraft_catalog::PhotoId(id)).is_none_or(|p| p.deleted) {- return Some(Err(format!("no photo {id}")));+ match app.session.catalog.photo(lightcraft_catalog::PhotoId(id)) {+ None => return Some(Err(format!("no photo {id}"))),+ Some(p) if p.deleted => return Some(Err(format!("photo {id} is in Recently Deleted: restore it to use it as the reference"))),+ Some(_) => {}}app.ui.reference = Some(id);Ok(json!({"reference": id}))diff --git a/crates/ui-egui/src/panels/compare.rs b/crates/ui-egui/src/panels/compare.rsindex 965bfb5b7..1ef368549 100644--- a/crates/ui-egui/src/panels/compare.rs+++ b/crates/ui-egui/src/panels/compare.rs@@ -23,11 +23,15 @@ pub fn culling(app: &LightcraftApp) -> bool {/// The (select, candidate) pair, repaired or chosen if needed: the active photo against the next/// selected photo, else against its neighbour in the view.+/// A photo that can be shown or pinned: in the catalog and not in Recently Deleted.+pub fn live(app: &LightcraftApp, id: PhotoId) -> bool {+ app.session.catalog.photo(id).is_some_and(|p| !p.deleted)+}+pub fn compare_pair(app: &mut LightcraftApp) -> Option<(PhotoId, PhotoId)> {- let exists = |app: &LightcraftApp, id: PhotoId| app.session.catalog.photo(id).is_some_and(|p| !p.deleted);if let Some((a, b)) = app.ui.compare {let (a, b) = (PhotoId(a), PhotoId(b));- if a != b && exists(app, a) && exists(app, b) {+ if a != b && live(app, a) && live(app, b) {return Some((a, b));}}@@ -450,10 +454,15 @@ pub fn prepare(app: &mut LightcraftApp) {app.renderer.release(Slot::Region);app.renderer.release(Slot::RegionBefore);}- if matches!(app.ui.view, ViewMode::Compare | ViewMode::Reference) {+ // Reference with no live pin draws no panes: release them as other views do.+ let reference_shown = app.ui.reference.is_some_and(|r| live(app, PhotoId(r)));+ if app.ui.view == ViewMode::Compare || (app.ui.view == ViewMode::Reference && reference_shown) {app.session.media.set_full_capacity(WINDOW_PANES as usize);return;}+ if app.ui.view == ViewMode::Reference {+ app.renderer.release(Slot::Compare(0));+ }app.session.media.set_full_capacity(1);for i in 0..WINDOW_PANES {if app.compare_windows[i as usize].take().is_some() || app.renderer.textures.contains_key(&Slot::CompareRegion(i)) {@@ -578,7 +587,7 @@ pub fn show_survey(app: &mut LightcraftApp, ui: &mut egui::Ui) {/// the Edit panel works on, so a look can be matched by eye.pub fn show_reference(app: &mut LightcraftApp, ui: &mut egui::Ui) {let canvas = area_and_filmstrip(app, ui);- let reference = app.ui.reference.map(PhotoId).filter(|r| app.session.catalog.photo(*r).is_some_and(|p| !p.deleted));+ let reference = app.ui.reference.map(PhotoId).filter(|r| live(app, *r));let (Some(r), Some(active)) = (reference, app.session.active()) else {super::empty_message(ui, canvas, "No reference photo", "Right-click a photo ▸ Set as Reference Photo, then View → Reference View (Shift+R)");return;diff --git a/crates/ui-egui/src/panels/grid.rs b/crates/ui-egui/src/panels/grid.rsindex 8ec5fd6e4..5a1e8527a 100644--- a/crates/ui-egui/src/panels/grid.rs+++ b/crates/ui-egui/src/panels/grid.rs@@ -1082,8 +1082,14 @@ pub fn context_menu(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {Err(e) => app.toast(ui.ctx(), e),}}- if ui.button(crate::i18n::tr("Set as Reference Photo")).clicked() {- let _ = app.run("photo.setReference", json!({"id": id.0}));+ let live = super::compare::live(app, id);+ let set_reference = ui+ .add_enabled(live, egui::Button::new(crate::i18n::tr("Set as Reference Photo")))+ .on_disabled_hover_text(crate::i18n::tr("Restore the photo to use it as the reference"));+ if set_reference.clicked()+ && let Err(e) = app.run("photo.setReference", json!({"id": id.0}))+ {+ app.toast(ui.ctx(), e);}ui.separator();crate::widgets::menu_button(ui, crate::i18n::tr("Set Rating"), |ui| {diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rsindex 6de4071a8..d1da36555 100644--- a/crates/ui-egui/src/panels/settings.rs+++ b/crates/ui-egui/src/panels/settings.rs@@ -1129,7 +1129,6 @@ fn switch_library(app: &mut LightcraftApp, path: &str) -> Result<Value, String>app.ui.dialog = None;}app.renderer.forget_all();- app.ui.compare = None;if let Err(err) = opened {let Some(prev) = previous_dir else { return Err(err) };return match app.session.open_library(&prev, false) {@@ -1137,8 +1136,13 @@ fn switch_library(app: &mut LightcraftApp, path: &str) -> Result<Value, String>Err(e) => Err(format!("{err}; reopening the previous library {} failed too: {e}", prev.display())),};}- // Photo IDs are local to a catalog: a pin cannot follow them into another library.+ // Photo IDs are local to a catalog: pins cannot follow them into another library (a refused+ // or failed switch reopens the same catalog, so its pins stay).app.ui.reference = None;+ app.ui.compare = None;+ if app.ui.view == crate::state::ViewMode::Reference {+ app.ui.view = crate::state::ViewMode::PhotoGrid;+ }app.ui.settings.library_path = path.clone();if let Some(prev) = previous.filter(|p| p != &path && !app.ui.settings.recent_libraries.contains(p)) {remember_library(&mut app.ui.settings.recent_libraries, &prev);diff --git a/crates/ui-egui/src/tests_compare.rs b/crates/ui-egui/src/tests_compare.rsindex 6d2a8eb5b..9f1038e53 100644--- a/crates/ui-egui/src/tests_compare.rs+++ b/crates/ui-egui/src/tests_compare.rs@@ -243,6 +243,17 @@ fn invalid_or_deleted_reference_is_refused_without_replacing_the_pin() {assert!(r.is_err(), "unavailable photo {id} must not be pinned");assert_eq!(h.app.ui.reference, Some(ids[0].0));}+ let deleted = h.app.run("photo.setReference", json!({"id": ids[1].0})).unwrap_err();+ assert!(deleted.contains("Recently Deleted"), "the caller learns to restore it: {deleted}");+ // a malformed id is refused, not taken for "the active photo"+ h.app.run("library.select", json!({"ids": [ids[2].0]})).unwrap();+ for id in [json!(ids[2].0.to_string()), json!(-1), json!(1.5), json!([ids[2].0])] {+ assert!(h.app.run("photo.setReference", json!({"id": id})).is_err(), "{id}");+ assert_eq!(h.app.ui.reference, Some(ids[0].0));+ }+ h.app.run("photo.setReference", json!({"id": null})).unwrap();+ assert_eq!(h.app.ui.reference, Some(ids[2].0), "a null id means the active photo");+ h.app.run("photo.setReference", json!({"id": ids[0].0})).unwrap();h.app.run("library.select", json!({"ids": []})).unwrap();assert!(h.app.run("photo.setReference", json!({})).is_err());assert_eq!(h.app.ui.reference, Some(ids[0].0));@@ -262,6 +273,8 @@ fn deleting_the_pinned_reference_stops_drawing_it_and_reentry_uses_a_live_photo(h.app.run("photo.delete", json!({"ids": [reference.0]})).unwrap();h.settle(SETTLE);assert!(!drawn(&h), "Recently Deleted photos must not remain on the reference canvas");+ assert!(!h.app.renderer.textures.contains_key(&crate::render::Slot::Compare(0)), "the deleted reference's pane is released");+ assert!(h.app.compare_windows[0].is_none());let r = h.app.run("view.reference", json!({})).unwrap();assert_eq!(r["reference"], active.0);assert_eq!(h.app.ui.reference, Some(active.0));diff --git a/crates/ui-egui/src/tests_switch_library.rs b/crates/ui-egui/src/tests_switch_library.rsindex d03ec7a9e..2ea310b04 100644--- a/crates/ui-egui/src/tests_switch_library.rs+++ b/crates/ui-egui/src/tests_switch_library.rs@@ -200,10 +200,12 @@ fn reference_photo_ids_do_not_cross_library_boundaries() {let held = lightcraft_catalog::LibraryLock::acquire(&second, "another program").unwrap();assert!(app.run("app.openLibrary", json!({"path": second.to_string_lossy()})).is_err());assert_eq!(app.ui.reference, Some(old_reference.0), "a refused switch keeps the live pin");+ assert_eq!(app.ui.view, crate::state::ViewMode::Reference);drop(held);app.run("app.openLibrary", json!({"path": second.to_string_lossy()})).unwrap();assert!(app.session.catalog.photo(old_reference).is_some(), "the second library reuses this numeric ID");assert_eq!(app.ui.reference, None, "the first library's pin must not acquire a different photo");+ assert_eq!(app.ui.view, crate::state::ViewMode::PhotoGrid, "an empty Reference view is not left on screen");app.run("library.select", json!({"ids": [new_photo.0]})).unwrap();let r = app.run("view.reference", json!({})).unwrap();assert_eq!(r["reference"], new_photo.0);diff --git a/docs/parity-checklist.md b/docs/parity-checklist.mdindex b0fad5a3d..1947c77ac 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-20 · **Change:** minor (LR-VIEW-ZOOM: only a full-size drag within 20 ms clears a slow-drag verdict) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; catalog-local pins; deleted and malformed references refused) · **Target:** Adobe Lightroom Classic 15.5 / Lightroom 9.6The measured, row-by-row checklist: one row per Lightroom feature, menu item and shortcut, what wehave and what is missing. It answers *does the feature exist?* (feature breadth). Whether it is good@@ -880,7 +880,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove| 2026-10-13 | minor | LR-META-INFO: Nikon DSLR raws show their lens from the maker note; status unchanged (✅) || 2026-10-13 | patch | LR-IMP-LOCAL: browsing a Local folder again forgets the untouched records of files deleted or moved by another app (issue #1392); status unchanged || 2026-10-13 | minor | LR-MERGE-PANO: a panorama keeps its photos' resolution (up to 512 MP / 65,000 px) instead of a fixed 40 MP, held to what fits in memory (issue #1455); status unchanged |-| 2026-10-11 | minor | LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; reference pins stay within their catalog, unavailable photos refused, deleted reference not drawn; statuses unchanged |+| 2026-10-21 | minor | LRC-LIB-REFVIEW / CATALOG-SWITCH: Escape preserves edits; reference pins stay within their catalog, unavailable or malformed photo ids refused, deleted reference not drawn and its pane released, a switch leaves Reference view; statuses unchanged || 2026-10-11 | minor | KEY-SLIDER-TYPE: honor immediate Return/Escape and keep typed keys in the value editor; add regression references || 2026-10-11 | minor | LR-PROF-CAMERACOLOR: raws with a black-and-white camera JPEG take its tone curve (issue #577) || 2026-10-11 | minor | LR-VIEW-ZOOM and LR-VIEW-COMPARE: Compare and Reference are sharp at 1:1 (zoom windows per pane, two originals kept decoded while they are open); statuses unchanged |diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex 37fce85dc..c46c38a66 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -156,6 +156,6 @@ establish OS keyboard delivery or cross-platform acceptance.| 2026-10-13 | minor | Shortcuts: Home / End and Shift+Left / Right in the two library grids, Cmd+O (Open Library…) and Shift+H (Visualize HDR) get bindings and keyboard tests; percentages and the dated counts above are unchanged || 2026-10-14 | minor | Zoom row: soft proofing gets zoom windows; LR-VIEW-ZOOM gap closed || 2026-10-12 | minor | Accessibility: an AccessKit tree audit test over every view, Develop tool and 13 dialogs; unnamed fields, slider ranges and the Auto Stack slider fixed; 30% → 55%; UI remaining 40–70 h → 34–58 h |-| 2026-10-11 | minor | Reference Escape exits to Detail; catalog-local pins and missing/deleted reference handling verified with regressions and native Windows smoke |+| 2026-10-21 | minor | Reference Escape exits to Detail; catalog-local pins and missing/deleted reference handling verified with regressions and native Windows smoke || 2026-10-11 | minor | Zoom row: Compare and Reference get zoom windows; what remains of LR-VIEW-ZOOM is overlays and soft proofing || 2026-10-10 | major | Created: measured command and shortcut counts, assessment by area, estimates; moved the shortcut conflicts section here from the checklist |diff --git a/docs/whats-new.md b/docs/whats-new.mdindex 971cc8097..b08a3edf0 100644--- a/docs/whats-new.md+++ b/docs/whats-new.md@@ -1,5 +1,20 @@# What's new in LightCraft+## 2026-10-21++### Reference view reliability+- Escape now leaves Reference for Detail without changing the active photo or its edits; the next+ Escape returns to the grid. A dialog, tool or Lights Out still handles Escape first.+- Opening or creating a different library clears the pinned reference. Photo IDs belong to one+ catalog; a pin no longer silently becomes another library's photo with the same numeric ID.+- Missing or Recently Deleted photos cannot be pinned. Deleting the pinned reference stops drawing+ it; re-entering Reference chooses a live photo, and restoring the deleted photo makes it pinnable again.+ In Recently Deleted, Set as Reference Photo is greyed out, and a refusal says to restore the photo.+- Switching library from Reference view goes to the grid instead of an empty Reference canvas. A refused+ or failed switch keeps both the reference and the Compare pair.+- `photo.setReference` refuses an `id` that is not a photo id (a string, a negative or fractional+ number) instead of pinning the active photo; only an absent or null `id` means the active photo.+## 2026-10-19### Hidden Local locations come back one at a time@@ -570,14 +585,6 @@D7000, D5100, D800, D800E, Df, D4, D3, D3S, D700, D300, D300S, D600, D610, D810, D4S, D5600, Coolpix A, D3000, D40X,D60, D80 and D2Xs now show the area the camera itself frames, a few pixels smaller than before.-### Reference view reliability-- Escape now leaves Reference for Detail without changing the active photo or its edits; the next- Escape returns to the grid. A dialog, tool or Lights Out still handles Escape first.-- Opening or creating a different library clears the pinned reference. Photo IDs belong to one- catalog; a pin no longer silently becomes another library's photo with the same numeric ID.-- Missing or Recently Deleted photos cannot be pinned. Deleting the pinned reference stops drawing- it; re-entering Reference chooses a live photo, and restoring the deleted photo makes it pinnable again.-### JPEG XL export- Export as JPEG XL (issue #247): Format ▸ JPEG XL in the Export dialog, `format: "jxl"` for agents and the CLI(`render in.raw -o out.jxl`). Quality as for JPEG, or Lossless; Effort (Fast / Normal) trades time for a