PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Tools: Shift key switches tools by default, as in Photoshop (#3525) (#3528)
Valentin Klein5e0a6d404d3b
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rsindex 39e283f66..93a52d2d1 100644--- a/crates/engine/src/prefs.rs+++ b/crates/engine/src/prefs.rs@@ -345,7 +345,7 @@ impl Default for Workspace {#[serde(default, rename_all = "camelCase")]pub struct Tools {pub show_tooltips: bool,- /// Tool keys cycle a tool group only with ⇧ held (Photoshop's "Use Shift Key for Tool Switch").+ /// Tool keys cycle a tool group only with ⇧ held (Photoshop's "Use Shift Key for Tool Switch", on by default there too).pub use_shift_key_for_tool_switch: bool,pub zoom_clicked_point_to_center: bool,pub enable_flick_panning: bool,@@ -372,7 +372,7 @@ impl Default for Tools {fn default() -> Self {Self {show_tooltips: true,- use_shift_key_for_tool_switch: false,+ use_shift_key_for_tool_switch: true,zoom_clicked_point_to_center: false,enable_flick_panning: true,vary_round_brush_hardness_on_hud: true,diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rsindex d19547f87..6bb34a970 100644--- a/crates/engine/src/prefs/tests.rs+++ b/crates/engine/src/prefs/tests.rs@@ -613,3 +613,13 @@ fn ruler_units_round_to_their_own_decimal_places() {let r = super::UnitsAndRulers { rulers: Unit::Inches, ..Default::default() };assert_eq!(r.format(100.0, 300.0, 1500.0), "0.333");}++/// #3296: like Photoshop, "Use Shift Key for Tool Switch" is on by default; a stored choice wins.+#[test]+fn shift_key_tool_switch_is_on_by_default_and_a_stored_false_is_kept() {+ assert!(Preferences::default().tools.use_shift_key_for_tool_switch);+ let missing: Tools = serde_json::from_value(json!({"showTooltips": false})).unwrap();+ assert!(missing.use_shift_key_for_tool_switch, "a settings file without the key gets the new default");+ let stored: Tools = serde_json::from_value(json!({"useShiftKeyForToolSwitch": false})).unwrap();+ assert!(!stored.use_shift_key_for_tool_switch);+}diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rsindex c5545af73..a660a92dd 100644--- a/crates/ui-egui/src/marquee_tests.rs+++ b/crates/ui-egui/src/marquee_tests.rs@@ -766,7 +766,7 @@ fn m_cycles_only_the_rectangular_and_elliptical_marquee() {let mut seen = Vec::new();for _ in 0..4 {let raw = egui::RawInput {- events: vec![egui::Event::Key { key: egui::Key::M, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }],+ events: vec![egui::Event::Key { key: egui::Key::M, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT }],..Default::default()};ctx.begin_pass(raw);diff --git a/crates/ui-egui/src/pencil_tests.rs b/crates/ui-egui/src/pencil_tests.rsindex 2b6f461b5..d5557c529 100644--- a/crates/ui-egui/src/pencil_tests.rs+++ b/crates/ui-egui/src/pencil_tests.rs@@ -223,6 +223,7 @@ fn b_cycles_brush_pencil_mixer_brush_and_color_replacement() {app});h.state_mut().ui.tool = Tool::Move;+ h.state_mut().session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false);h.run_steps(4);let press = |h: &mut Harness<'_, PhotocraftApp>, m: Modifiers| {h.event(egui::Event::Key { key: Key::B, physical_key: None, pressed: true, repeat: false, modifiers: m });diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rsindex 3b1b64242..00280102b 100644--- a/crates/ui-egui/src/shortcuts.rs+++ b/crates/ui-egui/src/shortcuts.rs@@ -576,6 +576,8 @@ mod tests {handle(app, &ctx);ctx.end_pass().textures_delta.clear();};+ // Plain-key cycling (the pref is on by default, as in Photoshop).+ app.session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false);// Polygonal Lasso picked from the toolbar flyout, then the Brush (#2608).app.ui.tool = Tool::PolygonLasso;press(&mut app, Key::B, Modifiers::NONE);@@ -596,6 +598,37 @@ mod tests {assert_eq!(app.ui.tool, Tool::MagneticLasso);}+ /// #3296: by default T keeps the current type tool and only Shift+T cycles, as in Photoshop.+ #[test]+ fn shift_key_tool_switch_is_the_default() {+ use crate::state::Tool;+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());+ let ctx = egui::Context::default();+ let press = |app: &mut PhotocraftApp, modifiers| {+ let raw = egui::RawInput {+ events: vec![+ egui::Event::ModifiersChanged(modifiers),+ egui::Event::Key { key: Key::T, physical_key: None, pressed: true, repeat: false, modifiers },+ ],+ ..Default::default()+ };+ ctx.begin_pass(raw);+ handle(app, &ctx);+ ctx.end_pass().textures_delta.clear();+ };+ app.ui.tool = Tool::Type;+ press(&mut app, Modifiers::NONE);+ press(&mut app, Modifiers::NONE);+ assert_eq!(app.ui.tool, Tool::Type);+ press(&mut app, Modifiers::SHIFT);+ assert_ne!(app.ui.tool, Tool::Type);+ // A stored "off" restores plain-key cycling.+ app.session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false);+ app.ui.tool = Tool::Type;+ press(&mut app, Modifiers::NONE);+ assert_ne!(app.ui.tool, Tool::Type);+ }+/// #3109: on a German layout Ö / # (physical `;` / `\`) step the brush size and ⇧Ö / ⇧#/// (⇧# types `'`) its hardness, as Photoshop's German shortcuts.#[test]diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex cb8746b6f..147125519 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -49,7 +49,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme| Toolbar behaviour | Status | Evidence ||---|---|---|-| Letter shortcuts, ⇧+letter cycles the group, "Use Shift Key for Tool Switch" | done | `shortcuts.rs:413` |+| Letter shortcuts, ⇧+letter cycles the group, "Use Shift Key for Tool Switch" (on by default, as in Photoshop) | done | `shortcuts.rs:413` || Group remembers the last tool used | partial | L always resets to Lasso (#2608) || Press-and-hold or click-drag opens the flyout | missing | right-click only (#2301) || Edit Toolbar customization | done | `edit.toolbar` |