Allow Enter to open crop editing for the selected layer

This commit is contained in:
Dandaedre 2026-11-18 16:05:07 +01:00
parent 6f5c24ed6b
commit 4ab2a2e855
5 changed files with 70 additions and 5 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.9.68"
version = "0.9.69"
dependencies = [
"base64 0.22.1",
"craft-dwg",

View File

@ -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"

View File

@ -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] {

View File

@ -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.

View File

@ -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.