mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Fix-up #9739: Reset under W x H x Resolution leaves nothing to reset
From CodeRabbit: with an output-size preset, Reset fits the frame and keeps it a pending crop (so Commit still crops), but Reset stayed enabled for that unchanged frame. Reset now remembers the frame it left; the button is live again once the frame changes. The merge with #11011 also keeps the Selection entry's flag when Reset frames a selection again. New test, which fails without the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a878ed36f8
commit
0d10ff57af
2 files changed
+29
-1
No files matched your search
@@ -58,6 +58,9 @@ pub struct CropState {
|
||||
/// while this matches. Keyed by id, not tab index, so closing it never hides the frame of the
|
||||
/// tab that takes its place.
|
||||
dismissed: Option<(photocraft_doc::DocId, u32, u32)>,
|
||||
/// The pending frame [`reset`] left when a W x H x Resolution preset kept it a crop: Reset
|
||||
/// stays disabled while the frame is still that one.
|
||||
reset_to: Option<[f64; 4]>,
|
||||
/// The frame is being edited (pressed since it was made): the canvas shows what lies past it.
|
||||
pub editing: bool,
|
||||
/// The document the pending frame (or gesture) belongs to ([`cancel_stale`], #1918).
|
||||
@@ -541,7 +544,10 @@ fn dismiss_key(app: &PhotocraftApp) -> Option<(photocraft_doc::DocId, u32, u32)>
|
||||
/// The frame was drawn, moved, resized or turned since it was last framed by default, so
|
||||
/// [`reset`] has something to undo.
|
||||
pub fn modified(app: &PhotocraftApp) -> bool {
|
||||
app.ui.tool == Tool::Crop && app.ui.crop_rect.is_some() && app.crop.drag.is_none() && (!app.crop.default_frame || app.ui.crop_angle != 0.0)
|
||||
app.ui.tool == Tool::Crop
|
||||
&& app.ui.crop_rect.is_some()
|
||||
&& app.crop.drag.is_none()
|
||||
&& (app.ui.crop_angle != 0.0 || (!app.crop.default_frame && app.ui.crop_rect != app.crop.reset_to))
|
||||
}
|
||||
|
||||
/// Reset the crop box (the options bar's Reset): the default frame again, upright, with the
|
||||
@@ -564,6 +570,9 @@ pub fn reset(app: &mut PhotocraftApp) {
|
||||
crate::crop_straighten::reset(app);
|
||||
// As a new default frame is: held to the ratio preset (or output size) picked in the bar.
|
||||
fit_frame(app);
|
||||
// A W x H x Resolution preset keeps the reset frame a pending crop (`fit_frame`), so remember
|
||||
// it: Reset has nothing more to do until it changes.
|
||||
app.crop.reset_to = app.ui.crop_rect.filter(|_| !app.crop.default_frame);
|
||||
if step_of(app) != before {
|
||||
app.crop.undo.push(before);
|
||||
app.crop.redo.clear();
|
||||
|
||||
@@ -169,6 +169,25 @@ fn reset_holds_the_frame_to_the_ratio_preset() {
|
||||
assert_eq!(app.ui.crop_rect, drawn, "Undo brings the drawn frame back");
|
||||
}
|
||||
|
||||
/// A W x H x Resolution preset keeps the reset frame a pending crop (it sets an output size), so
|
||||
/// Commit still crops; Reset has nothing more to do on it until the frame changes again.
|
||||
#[test]
|
||||
fn reset_under_an_output_size_leaves_nothing_to_reset() {
|
||||
let mut app = app(SampleType::U8);
|
||||
ensure_frame(&mut app);
|
||||
let o = &mut app.ui.tool_options;
|
||||
o.crop_ratio = crate::crop_size::WHR.into();
|
||||
(o.crop_width, o.crop_height, o.crop_resolution) = ("100 px".into(), "100 px".into(), "72".into());
|
||||
drag(&mut app, &[[50.0, 20.0], [80.0, 40.0], [120.0, 70.0]], NONE);
|
||||
assert!(modified(&app));
|
||||
reset(&mut app);
|
||||
assert_eq!(app.ui.crop_rect, Some([50.0, 0.0, 150.0, 100.0]));
|
||||
assert!(pending(&app), "the output size is still a crop to commit");
|
||||
assert!(!modified(&app), "and Reset has nothing more to do");
|
||||
drag(&mut app, &[[60.0, 10.0], [90.0, 40.0]], NONE);
|
||||
assert!(modified(&app), "a new frame can be reset again");
|
||||
}
|
||||
|
||||
/// #9730: the Crop tool's options bar has a Reset button beside Cancel and Commit, live once
|
||||
/// the frame was changed.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user