From 4ab2a2e855752220ba1f0901f7cb8e83f42753ca Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 18 Nov 2026 16:05:07 +0100 Subject: [PATCH] Allow Enter to open crop editing for the selected layer --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/canvas-pilot/src/gui.rs | 61 ++++++++++++++++++++- docs/canvas-pilot/changelog.md | 7 +++ docs/canvas-pilot/guide/formats-and-crop.md | 3 +- 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0963b77..68e3a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,7 +602,7 @@ dependencies = [ [[package]] name = "canvas-pilot" -version = "0.9.68" +version = "0.9.69" dependencies = [ "base64 0.22.1", "craft-dwg", diff --git a/Cargo.toml b/Cargo.toml index a16030d..563b67e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"] resolver = "3" [workspace.package] -version = "0.9.68" +version = "0.9.69" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot" diff --git a/crates/canvas-pilot/src/gui.rs b/crates/canvas-pilot/src/gui.rs index d800bf0..23d1f22 100644 --- a/crates/canvas-pilot/src/gui.rs +++ b/crates/canvas-pilot/src/gui.rs @@ -485,7 +485,6 @@ impl Editor { return; } let eligible = !self.inputs.open - && self.edit_content && self.navigation_tool == NavigationTool::Select && !self.layout.dragging() && !self.panning @@ -518,6 +517,7 @@ impl Editor { .selected() .is_some_and(|i| !self.layout.locked(i) && self.layout.visible(i)); let tab_eligible = eligible + && self.edit_content && self.format_draft.is_none() && self.layout.selected().is_some_and(|i| { self.layout.formats().layer_fit[i] @@ -541,7 +541,11 @@ impl Editor { self.crop_mask_enter_held = *pressed; if enter_eligible && modifiers.is_none() { if *pressed && !was_held { - self.finish_crop_edit(); + if self.edit_content { + self.finish_crop_edit(); + } else { + self.toggle_crop_edit(); + } } return false; } @@ -6637,6 +6641,59 @@ mod tests { assert!(app.edit_content); } + #[test] + fn enter_opens_crop_and_release_is_required_before_closing() { + for fit in [None, Some(canvas_pilot::formats::LayerFit::OneToOne)] { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + app.layout.select(Some(1)); + app.layout + .set_layer_fit(1, fit, Default::default()) + .unwrap(); + let before = app.project(); + let mut input = egui::RawInput { + events: vec![key(egui::Key::Enter)], + ..Default::default() + }; + app.crop_mask_key_input(&ctx, &mut input); + assert!(app.edit_content); + assert!(input.events.is_empty()); + input.events = vec![key(egui::Key::Enter)]; + app.crop_mask_key_input(&ctx, &mut input); + assert!(app.edit_content); + let mut release = key(egui::Key::Enter); + if let egui::Event::Key { pressed, .. } = &mut release { + *pressed = false; + } + input.events = vec![release, key(egui::Key::Enter)]; + app.crop_mask_key_input(&ctx, &mut input); + assert!(!app.edit_content); + assert_eq!(app.project(), before); + } + } + + #[test] + fn enter_does_not_open_crop_while_typing_or_in_input_settings() { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + app.layout.select(Some(1)); + let field = egui::Id::new("typing-field"); + ctx.memory_mut(|m| m.request_focus(field)); + let mut input = egui::RawInput { + events: vec![key(egui::Key::Enter)], + ..Default::default() + }; + app.crop_mask_key_input(&ctx, &mut input); + assert!(!app.edit_content); + assert_eq!(input.events.len(), 1); + ctx.memory_mut(|m| m.surrender_focus(field)); + app.crop_mask_enter_held = false; + app.inputs.open = true; + app.crop_mask_key_input(&ctx, &mut input); + assert!(!app.edit_content); + assert_eq!(input.events.len(), 1); + } + #[test] fn enter_finishes_crop_and_mask_without_changing_live_edits_or_undo() { for mask in [false, true] { diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index db84531..4c2669f 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -4,6 +4,13 @@ ## Unreleased +### v0.9.69 + +- Enter now opens crop edit for the selected editable layer using the same rules + as double-click, and finishes an active crop/mask edit. Text fields, dialogs, + active drags and held-key repeats retain their existing safeguards. + + ### v0.9.68 - Moved **Send changes**, validation feedback and status above the input editor. diff --git a/docs/canvas-pilot/guide/formats-and-crop.md b/docs/canvas-pilot/guide/formats-and-crop.md index 3dc4e30..e8b9a10 100644 --- a/docs/canvas-pilot/guide/formats-and-crop.md +++ b/docs/canvas-pilot/guide/formats-and-crop.md @@ -253,7 +253,8 @@ they are never exported or sent to the device. It works with normal crop and eve - Enter Left/Right/Top/Bottom distances in output pixels. - The alignment menu aligns the mask window to the selected reference’s edges or center. - **Center mask** preserves its size; **Reset mask** removes all blanking. -- **Enter** finishes crop/mask editing and keeps the live changes. When typing in +- **Enter** opens crop editing for the selected editable layer, just like + double-click. Press it again to finish crop/mask editing and keep the live changes. When typing in a numeric field, Enter confirms that value first; press Enter again after leaving the field to finish. Other unapplied properties use the existing Apply/Discard review, so finishing cannot silently discard them.