Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

feat(ui): spring-loaded tool letters (#2672) (#4238)

FinnNk96f4d68db713
diff --git a/crates/ui-egui/src/artboard_tool.rs b/crates/ui-egui/src/artboard_tool.rs
index 79a7cd3b7..6b996c3f1 100644
--- a/crates/ui-egui/src/artboard_tool.rs
+++ b/crates/ui-egui/src/artboard_tool.rs
@@ -417,7 +417,11 @@ mod tests {
let press = |app: &mut PhotocraftApp, modifiers| {
let key = egui::Key::V;
let raw = egui::RawInput {
- events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],
+ events: vec![
+ egui::Event::ModifiersChanged(modifiers),
+ egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers },
+ egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers },
+ ],
..Default::default()
};
ctx.begin_pass(raw);
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index b053af1a4..38d1e33f6 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2903,6 +2903,10 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
// Under an open dialog the canvas widget is inert, but the image still pans and zooms.
let under_dialog = !app.ui.dialogs.is_empty();
let free_hover = under_dialog && crate::dialogs::free_pointer_over(&ctx, rect).is_some();
+ // A press on the canvas while a tool letter is held makes that tool temporary (#2672).
+ if !under_dialog && ctx.input(|i| i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| rect.contains(p))) {
+ crate::spring_tools::note_canvas_press(app);
+ }
// Navigation (wheel_nav.rs): scroll pans (⇧ or ⌘/Ctrl sideways); pinch and ⌥-scroll zoom around the pointer.
let wheel =
crate::wheel_nav::read(&ctx, app.session.prefs().general.zoom_with_scroll_wheel, app.session.prefs().enhanced_controls.zoom_with_trackpad_pinch);
diff --git a/crates/ui-egui/src/hold_keys/tests.rs b/crates/ui-egui/src/hold_keys/tests.rs
index d558a5a7b..cfe89d464 100644
--- a/crates/ui-egui/src/hold_keys/tests.rs
+++ b/crates/ui-egui/src/hold_keys/tests.rs
@@ -72,9 +72,15 @@ fn key(h: &mut Harness<'static, PhotocraftApp>, k: Key, pressed: bool, m: Modifi
h.run_steps(1);
}
+/// A quick press and release in one frame (a tool letter held across frames springs, #2672).
fn tap(h: &mut Harness<'static, PhotocraftApp>, k: Key, m: Modifiers) {
- key(h, k, true, m);
- key(h, k, false, m);
+ let m = platform(m);
+ h.input_mut().events.extend([
+ Event::ModifiersChanged(m),
+ Event::Key { key: k, physical_key: None, pressed: true, repeat: false, modifiers: m },
+ Event::Key { key: k, physical_key: None, pressed: false, repeat: false, modifiers: m },
+ ]);
+ h.run_steps(1);
h.event(Event::ModifiersChanged(Modifiers::NONE));
h.run_steps(1);
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 05c49b60d..2bfa9e96f 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -175,6 +175,7 @@ pub mod slice_ui;
pub mod smart_ui;
pub mod snap_ui;
pub(crate) mod solid_fill_ui;
+pub mod spring_tools;
pub mod state;
pub mod stroke_constraint;
pub mod stroke_trail;
diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rs
index 241f5aa04..cf4832904 100644
--- a/crates/ui-egui/src/marquee_tests.rs
+++ b/crates/ui-egui/src/marquee_tests.rs
@@ -792,7 +792,10 @@ 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::SHIFT }],
+ events: vec![
+ egui::Event::Key { key: egui::Key::M, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT },
+ egui::Event::Key { key: egui::Key::M, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::SHIFT },
+ ],
..Default::default()
};
ctx.begin_pass(raw);
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 5b549d667..6e592385a 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -297,6 +297,8 @@ pub fn clipboard_keys(ctx: &egui::Context, typing: bool, raw: &mut egui::RawInpu
}
pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
+ // A held tool letter released: a temporary tool gives the previous one back (#2672).
+ crate::spring_tools::tick(app, ctx);
// However the tool was picked (toolbar, flyout, shortcut, automation), its group's key brings
// it back later (#2608).
app.ui.remember_group_tool();
@@ -573,17 +575,24 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
// Tool keys; pressing the key of the current group cycles within it. With Preferences ›
// Tools › Use Shift Key for Tool Switch, only ⇧+key cycles and the plain key keeps the
// group's current tool. From another group, the key picks the group's last-used tool.
+ // A held tool letter is a spring-loaded tool (#2672), not a burst of presses: its key
+ // repeats are dropped rather than cycling the group.
+ ctx.input_mut(|i| i.events.retain(|e| !matches!(e, egui::Event::Key { key, pressed: true, repeat: true, .. } if crate::spring_tools::is_tool_key(*key))));
let shift_switch = app.session.prefs().tools.use_shift_key_for_tool_switch;
for t in Tool::ALL {
- let Some(k) = Key::from_name(&t.key().to_string()) else { continue };
+ let Some(k) = crate::spring_tools::key_of(t.key()) else { continue };
let cycle_shift = shift_switch && ctx.input_mut(|i| i.consume_key(Modifiers::SHIFT, k));
if cycle_shift || pressed(k) {
+ let before = app.ui.tool;
let group: Vec<Tool> = Tool::ALL.iter().copied().filter(|x| x.key() == t.key()).collect();
app.ui.tool = match group.iter().position(|x| *x == app.ui.tool) {
Some(i) if shift_switch && !cycle_shift => group[i],
Some(i) => group[(i + 1) % group.len()],
None => app.ui.group_tool(t.key()).unwrap_or(group[0]),
};
+ // `consume_key` ignores extra ⇧ and ⌥: a ⇧/⌥ switch is never spring-loaded.
+ let (plain, now) = ctx.input(|i| (!cycle_shift && !i.modifiers.shift && !i.modifiers.alt, i.time));
+ crate::spring_tools::pressed(app, t.key(), before, plain, now);
return;
}
}
@@ -604,7 +613,11 @@ mod tests {
let ctx = egui::Context::default();
let press = |app: &mut PhotocraftApp, key, modifiers| {
let raw = egui::RawInput {
- events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],
+ events: vec![
+ egui::Event::ModifiersChanged(modifiers),
+ egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers },
+ egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers },
+ ],
..Default::default()
};
ctx.begin_pass(raw);
@@ -644,6 +657,7 @@ mod tests {
events: vec![
egui::Event::ModifiersChanged(modifiers),
egui::Event::Key { key: Key::T, physical_key: None, pressed: true, repeat: false, modifiers },
+ egui::Event::Key { key: Key::T, physical_key: None, pressed: false, repeat: false, modifiers },
],
..Default::default()
};
diff --git a/crates/ui-egui/src/spring_tools.rs b/crates/ui-egui/src/spring_tools.rs
new file mode 100644
index 000000000..5f51136cd
--- /dev/null
+++ b/crates/ui-egui/src/spring_tools.rs
@@ -0,0 +1,127 @@
+//! Spring-loaded tool keys (#2672): hold a tool's letter for a temporary tool.
+//!
+//! A tool letter switches tools when it is pressed, as before (`shortcuts::handle`). If the key is
+//! then held for [`SPRING_HOLD_SECS`] or longer, or the canvas is used while it is down, the switch
+//! was only temporary: releasing the key gives back the tool in effect before the press, with its
+//! options. A quick tap with no canvas use stays a permanent switch.
+//!
+//! - ⇧+letter (cycling the group) and ⌥+letter never spring; nor do letters while typing in a
+//! field, editing type or under a modal dialog, which never reach the tool keys.
+//! - Pressing the current group's own letter cycles the group, as a tap does, and doesn't spring.
+//! - A canvas drag still in progress when the key comes up finishes with the temporary tool; the
+//! previous tool returns once the button is up (as `hold_keys` latches Space).
+//! - Another letter pressed while one is held wins (newest first); releasing every held letter
+//! returns the original tool. Holding two letters at once counts as a hold.
+//! - Key repeats are not presses: `shortcuts::handle` drops them for tool letters.
+//!
+//! Z is one case: hold Z to zoom, add ⌥ to zoom out, as with the Zoom tool itself (and as
+//! `hold_keys` does for ⌥ with a held Zoom In).
+//!
+//! The state is [`crate::state::UiState::spring`], readable over the control channel.
+
+use egui::Key;
+use serde::{Deserialize, Serialize};
+
+use crate::PhotocraftApp;
+use crate::state::Tool;
+
+/// How long (seconds) a tool letter must stay down for its tool to be temporary.
+pub const SPRING_HOLD_SECS: f64 = 0.3;
+
+/// A tool switch made by a letter that is still down (or whose drag is still finishing).
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Spring {
+ /// The tool to give back.
+ pub previous: Tool,
+ /// The tool the held letter picked. If the tool changes any other way while it's held (the
+ /// toolbar, a menu, automation), that choice stands and nothing springs back.
+ pub tool: Tool,
+ /// The tool letters held, oldest first.
+ pub keys: Vec<char>,
+ /// `egui` input time of the first press.
+ pub since: f64,
+ /// The canvas was pressed (or a second letter pressed) while held: the switch is temporary
+ /// however short the hold.
+ pub used: bool,
+ /// Every letter is up and the switch is temporary, but a drag is still in progress.
+ pub released: bool,
+}
+
+/// The egui key of a tool letter (`None` for the tools without one).
+pub fn key_of(letter: char) -> Option<Key> {
+ if letter == '\0' {
+ return None;
+ }
+ Key::from_name(&letter.to_string())
+}
+
+/// Is `k` some tool's single-key shortcut?
+pub fn is_tool_key(k: Key) -> bool {
+ Tool::ALL.iter().any(|t| key_of(t.key()) == Some(k))
+}
+
+/// A tool letter switched the tool from `before` (the switch is already made). `plain` is false
+/// when ⇧ or ⌥ was held: those switches are permanent. `now` is the input time.
+pub fn pressed(app: &mut PhotocraftApp, letter: char, before: Tool, plain: bool, now: f64) {
+ let active = app.ui.spring.as_ref().is_some_and(|s| !s.released);
+ if !plain {
+ app.ui.spring = None;
+ return;
+ }
+ if active {
+ if let Some(s) = app.ui.spring.as_mut() {
+ s.keys.retain(|k| *k != letter);
+ s.keys.push(letter);
+ s.used = true;
+ s.tool = app.ui.tool;
+ }
+ return;
+ }
+ // The current group's own key cycles it (or keeps it), as a tap always has.
+ let tool = app.ui.tool;
+ app.ui.spring = (before.key() != letter).then(|| Spring { previous: before, tool, keys: vec![letter], since: now, used: false, released: false });
+}
+
+/// The canvas was pressed: a held letter's tool becomes temporary.
+pub fn note_canvas_press(app: &mut PhotocraftApp) {
+ if let Some(s) = app.ui.spring.as_mut().filter(|s| !s.released) {
+ s.used = true;
+ }
+}
+
+/// Once a frame, before the key handling: notice released letters and give the previous tool
+/// back when the switch was temporary and no drag is in progress.
+pub fn tick(app: &mut PhotocraftApp, ctx: &egui::Context) {
+ let Some(mut s) = app.ui.spring.take() else { return };
+ // Type editing begun with the temporary Type tool keeps it: the edit owns the tool now. So
+ // does a tool picked another way while the letter is down.
+ if app.ui.text_edit.is_some() || app.ui.tool != s.tool {
+ return;
+ }
+ let (now, button) = ctx.input(|i| (i.time, i.pointer.any_down()));
+ let dragging = app.drag.is_some() || button;
+ if !s.released {
+ if app.drag.is_some() {
+ s.used = true;
+ }
+ s.keys.retain(|k| key_of(*k).is_some_and(|k| ctx.input(|i| i.key_down(k))));
+ if !s.keys.is_empty() {
+ app.ui.spring = Some(s);
+ return;
+ }
+ if !s.used && now - s.since < SPRING_HOLD_SECS {
+ // A tap: the switch stands.
+ return;
+ }
+ s.released = true;
+ }
+ if dragging {
+ app.ui.spring = Some(s);
+ ctx.request_repaint();
+ return;
+ }
+ app.ui.tool = s.previous;
+}
+
+#[cfg(test)]
+mod tests;
diff --git a/crates/ui-egui/src/spring_tools/tests.rs b/crates/ui-egui/src/spring_tools/tests.rs
new file mode 100644
index 000000000..eef327c09
--- /dev/null
+++ b/crates/ui-egui/src/spring_tools/tests.rs
@@ -0,0 +1,269 @@
+//! #2672 through the real key handling and canvas: a tapped tool letter switches for good, a held
+//! one (or one used on the canvas) springs back on release.
+
+use egui::{Event, Key, Modifiers, PointerButton, Pos2, vec2};
+use egui_kittest::Harness;
+use serde_json::json;
+
+use super::*;
+use crate::canvas::ViewXform;
+
+/// Frames are 1/60 s apart, so a hold is a count of frames.
+const DT: f32 = 1.0 / 60.0;
+
+fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
+ app.sync_views();
+ app.ui.extras.rulers = false;
+ app.ui.tool = tool;
+ let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(DT).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ let ctx = ui.ctx().clone();
+ if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ return;
+ }
+ crate::shortcuts::handle(app, &ctx);
+ egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run_steps(4);
+ let v = &mut h.state_mut().ui.views[0];
+ v.zoom = 1.0;
+ v.center = [200.0, 150.0];
+ v.fit_pending = false;
+ h.run_steps(2);
+ h
+}
+
+fn screen(h: &Harness<'static, PhotocraftApp>, x: f32, y: f32) -> Pos2 {
+ let app = h.state();
+ let v = &app.ui.views[0];
+ let xf = ViewXform {
+ rect: crate::rulers::content_rect(app, app.last_canvas_rect),
+ zoom: v.zoom,
+ center: v.center,
+ flip: app.ui.view.flip_horizontal,
+ rotation: v.rotation,
+ aspect: app.ui.view.display_aspect(),
+ };
+ xf.to_screen(x, y)
+}
+
+/// One key event with its modifiers, run as a frame.
+fn key_event(h: &mut Harness<'static, PhotocraftApp>, k: Key, pressed: bool, repeat: bool, m: Modifiers) {
+ h.event(Event::ModifiersChanged(m));
+ h.event(Event::Key { key: k, physical_key: None, pressed, repeat, modifiers: m });
+ h.run_steps(1);
+}
+
+fn down(h: &mut Harness<'static, PhotocraftApp>, k: Key) {
+ key_event(h, k, true, false, Modifiers::NONE);
+}
+
+fn up(h: &mut Harness<'static, PhotocraftApp>, k: Key) {
+ key_event(h, k, false, false, Modifiers::NONE);
+ h.run_steps(2);
+}
+
+/// Wait `secs` of input time.
+fn wait(h: &mut Harness<'static, PhotocraftApp>, secs: f64) {
+ h.run_steps((secs / f64::from(DT)).ceil() as usize);
+}
+
+fn button(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, pressed: bool, m: Modifiers) {
+ h.event(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: m });
+ h.run_steps(1);
+}
+
+fn move_to(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32) {
+ let p = screen(h, x, y);
+ h.event(Event::PointerMoved(p));
+ h.run_steps(1);
+}
+
+fn click(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32, m: Modifiers) {
+ move_to(h, x, y);
+ let p = screen(h, x, y);
+ button(h, p, true, m);
+ button(h, p, false, m);
+}
+
+#[test]
+fn a_tap_switches_tools_for_good() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::E);
+ assert_eq!(h.state().ui.tool, Tool::Eraser);
+ assert!(h.state().ui.spring.is_some(), "the press is pending: tap or hold");
+ up(&mut h, Key::E);
+ assert_eq!(h.state().ui.tool, Tool::Eraser);
+ assert_eq!(h.state().ui.spring, None);
+}
+
+#[test]
+fn a_held_letter_gives_the_previous_tool_back() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::E);
+ wait(&mut h, SPRING_HOLD_SECS + 0.1);
+ assert_eq!(h.state().ui.tool, Tool::Eraser, "the temporary tool is the tool shown meanwhile");
+ up(&mut h, Key::E);
+ assert_eq!(h.state().ui.tool, Tool::Brush);
+ assert_eq!(h.state().ui.spring, None);
+}
+
+#[test]
+fn hold_z_click_zooms_then_a_quick_release_restores() {
+ let mut h = harness(Tool::Brush);
+ let z0 = h.state().ui.views[0].zoom;
+ down(&mut h, Key::Z);
+ click(&mut h, 200.0, 150.0, Modifiers::NONE);
+ up(&mut h, Key::Z);
+ let z1 = h.state().ui.views[0].zoom;
+ assert!(z1 > z0, "{z0} -> {z1}");
+ assert_eq!(h.state().ui.tool, Tool::Brush, "a canvas click makes even a short hold temporary");
+ assert!(!h.state().session.active().unwrap().history.can_undo(), "nothing was painted");
+ // ⌥ with a held Z zooms out, as ⌥ does with the Zoom tool.
+ down(&mut h, Key::Z);
+ h.event(Event::ModifiersChanged(Modifiers::ALT));
+ click(&mut h, 200.0, 150.0, Modifiers::ALT);
+ h.event(Event::ModifiersChanged(Modifiers::NONE));
+ up(&mut h, Key::Z);
+ assert!(h.state().ui.views[0].zoom < z1);
+ assert_eq!(h.state().ui.tool, Tool::Brush);
+}
+
+#[test]
+fn shift_letter_cycles_and_never_springs() {
+ let mut h = harness(Tool::Brush);
+ h.state_mut().session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = true);
+ key_event(&mut h, Key::B, true, false, Modifiers::SHIFT);
+ assert_eq!(h.state().ui.tool, Tool::Pencil);
+ assert_eq!(h.state().ui.spring, None);
+ wait(&mut h, SPRING_HOLD_SECS + 0.1);
+ key_event(&mut h, Key::B, false, false, Modifiers::SHIFT);
+ h.event(Event::ModifiersChanged(Modifiers::NONE));
+ h.run_steps(2);
+ assert_eq!(h.state().ui.tool, Tool::Pencil);
+
+ // Without the preference ⇧E is still a permanent switch, however long it is held.
+ let mut h = harness(Tool::Brush);
+ key_event(&mut h, Key::E, true, false, Modifiers::SHIFT);
+ wait(&mut h, SPRING_HOLD_SECS + 0.1);
+ key_event(&mut h, Key::E, false, false, Modifiers::SHIFT);
+ h.run_steps(2);
+ assert_eq!(h.state().ui.tool, Tool::Eraser);
+ assert_eq!(h.state().ui.spring, None);
+}
+
+#[test]
+fn key_repeats_are_not_presses() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::L);
+ assert_eq!(h.state().ui.tool, Tool::Lasso);
+ for _ in 0..8 {
+ key_event(&mut h, Key::L, true, true, Modifiers::NONE);
+ wait(&mut h, 0.05);
+ }
+ assert_eq!(h.state().ui.tool, Tool::Lasso, "repeats don't cycle the group");
+ up(&mut h, Key::L);
+ assert_eq!(h.state().ui.tool, Tool::Brush);
+}
+
+#[test]
+fn a_drag_keeps_the_temporary_tool_until_the_button_is_up() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::M);
+ assert_eq!(h.state().ui.tool, Tool::RectMarquee);
+ move_to(&mut h, 50.0, 50.0);
+ let p = screen(&h, 50.0, 50.0);
+ button(&mut h, p, true, Modifiers::NONE);
+ move_to(&mut h, 100.0, 90.0);
+ up(&mut h, Key::M);
+ assert_eq!(h.state().ui.tool, Tool::RectMarquee, "the drag finishes with the temporary tool");
+ move_to(&mut h, 150.0, 110.0);
+ let p = screen(&h, 150.0, 110.0);
+ button(&mut h, p, false, Modifiers::NONE);
+ h.run_steps(2);
+ assert_eq!(h.state().ui.tool, Tool::Brush);
+ assert_eq!(h.state().ui.spring, None);
+ let sel = h.state().session.active().unwrap().doc.selection.as_ref().map(|s| s.content_bounds());
+ assert!(sel.is_some_and(|r| r.width() > 50 && r.height() > 30), "{sel:?}");
+}
+
+#[test]
+fn the_newest_letter_wins_and_release_restores_the_original() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::E);
+ down(&mut h, Key::L);
+ assert_eq!(h.state().ui.tool, Tool::Lasso);
+ up(&mut h, Key::E);
+ assert_eq!(h.state().ui.tool, Tool::Lasso, "L is still held");
+ up(&mut h, Key::L);
+ assert_eq!(h.state().ui.tool, Tool::Brush);
+}
+
+#[test]
+fn letters_type_while_editing_text() {
+ let mut h = harness(Tool::Type);
+ let id = h.state_mut().run("type.create", json!({"x": 20, "y": 80, "text": "a", "size": 40})).unwrap()["layer"].as_u64().unwrap();
+ h.state_mut().ui.text_edit = Some(crate::state::TextEdit {
+ layer: id,
+ caret: 1,
+ anchor: 1,
+ session: "spring-test".into(),
+ created: false,
+ mask: false,
+ dragging: false,
+ resize: None,
+ preedit: None,
+ });
+ h.run_steps(2);
+ h.event(Event::Key { key: Key::B, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
+ h.event(Event::Text("b".into()));
+ h.run_steps(1);
+ wait(&mut h, SPRING_HOLD_SECS + 0.1);
+ up(&mut h, Key::B);
+ assert_eq!(h.state().ui.tool, Tool::Type);
+ assert_eq!(h.state().ui.spring, None);
+ let st = h.state().session.active().unwrap();
+ match &st.doc.layer(photocraft_doc::LayerId(id)).unwrap().content {
+ photocraft_doc::LayerContent::Text(t) => assert_eq!(t.text, "ab"),
+ _ => panic!("not text"),
+ }
+}
+
+/// A tool picked another way while a letter is held (here, as the toolbar would) stands: the release
+/// doesn't take it back.
+#[test]
+fn a_tool_picked_while_a_letter_is_held_stands() {
+ let mut h = harness(Tool::Brush);
+ down(&mut h, Key::E);
+ wait(&mut h, SPRING_HOLD_SECS + 0.1);
+ h.state_mut().ui.tool = Tool::Lasso;
+ up(&mut h, Key::E);
+ assert_eq!(h.state().ui.tool, Tool::Lasso);
+ assert_eq!(h.state().ui.spring, None);
+}
+
+#[test]
+fn plain_functions_follow_the_rules() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.ui.tool = Tool::Eraser;
+ // The current group's own key cycles; no spring.
+ pressed(&mut app, 'E', Tool::Eraser, true, 0.0);
+ assert_eq!(app.ui.spring, None);
+ // A ⇧ switch clears any pending spring.
+ pressed(&mut app, 'B', Tool::Eraser, true, 0.0);
+ assert!(app.ui.spring.is_some());
+ pressed(&mut app, 'L', Tool::Brush, false, 0.1);
+ assert_eq!(app.ui.spring, None);
+ // A canvas press marks a pending spring used; nothing to mark without one.
+ note_canvas_press(&mut app);
+ pressed(&mut app, 'B', Tool::Eraser, true, 0.0);
+ note_canvas_press(&mut app);
+ assert!(app.ui.spring.as_ref().is_some_and(|s| s.used && s.previous == Tool::Eraser));
+ assert_eq!(key_of('\0'), None);
+ assert!(is_tool_key(Key::Z) && !is_tool_key(Key::F1));
+}
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 02b4f005d..50f4b8b68 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -1033,6 +1033,10 @@ pub struct UiState {
/// one per group: the group's key brings it back, as in Photoshop (#2608).
#[serde(default)]
pub group_tools: Vec<Tool>,
+ /// A tool letter still held (spring-loaded tool, #2672): the tool to give back on release.
+ /// Exposed to automation, never restored from settings.
+ #[serde(default, skip_deserializing)]
+ pub spring: Option<crate::spring_tools::Spring>,
/// Recently opened file paths, most-recent first (File › Open Recent). Capped; de-duplicated.
#[serde(default)]
pub recent_files: Vec<String>,
@@ -1244,6 +1248,7 @@ impl Default for UiState {
Self {
tool: Tool::Brush,
group_tools: Vec::new(),
+ spring: None,
recent_files: Vec::new(),
text_edit: None,
type_transform: None,
diff --git a/docs/gaps.md b/docs/gaps.md
index 870613ae3..5a5068536 100644
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@ -1,6 +1,6 @@
# Where PhotoCraft falls short of Photoshop
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (refreshed against main: G2, G5, G7, G9, G10, G13, G14, G17 items that landed; G10: DPX read and write, #1049; G4: checkbox-only Brush Settings rows; G11: Load/Save Actions `.atn` landed, AUTO-219-2 partial; G5: hold-a-key spring-loaded tools landed, #2672) · **Target:** Adobe Photoshop 2026
Every known shortfall against Photoshop 2026 (27.11.0), one entry each, ranked by user impact
on the way to beta. This is the work list agents pick from: take the highest-ranked entry that
@@ -156,7 +156,7 @@ what an agent can't finish alone.
### G5. Transform, handles and modifiers
- **Missing:** H/V skew fields and the full interpolation list; blend mode/opacity edits during
a transform (#1384); path-point nudge; autoscroll at the edge while selecting (#2231);
- hold-a-key spring-loaded tools (#2672); wheel and pinch behaviour (#2485, #2463, #1989);
+ wheel and pinch behaviour (#2485, #2463, #1989);
toolbar press-and-hold flyouts (#2301).
- **Done since the re-measure (2026-10-10 to 12):** right-click menu during Free Transform
(TOOL-214-5); commit/cancel buttons in the options bar (#2442); transform keeps the layer's
@@ -164,7 +164,8 @@ what an agent can't finish alone.
locked layers refused before the drag (#2585, #2609); ⌘-drag temporary Move with box and
snapping (#2681, #2684); Auto-Select box follows the picked layer (#2666, #2675); ⌘-arrow
layer nudge (#2474, #2556); polygonal lasso Shift angles (#2352, #2396); double-click Zoom tool
- to 100% (#2508, #2527); tool-key memory in a group (#2608, #2625).
+ to 100% (#2508, #2527); tool-key memory in a group (#2608, #2625); hold-a-key spring-loaded
+ tools (#2672).
- **Detail:** [`ui-parity.md`](ui-parity.md).
- **Estimate:** 60–110 h.
@@ -239,6 +240,7 @@ what an agent can't finish alone.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-12 | minor | G5: spring-loaded tool letters done (#2672) |
| 2026-10-12 | minor | G10: DPX read and write (#1049); Cineon remains open |
| 2026-10-12 | minor | G4: checkbox-only Brush Settings rows preserve the open controls and Smoothing settings (#4283); no readiness percentage or estimate changed |
| 2026-10-12 | minor | G11: Load/Save Actions `.atn` landed (AUTO-219-2 partial); remaining panel work listed |
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 76b59de71..70b503d0c 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -161,7 +161,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| Behaviour | Status | Evidence |
|---|---|---|
| Space = Hand, ⌘Space / ⌘⌥Space = zoom in/out, spring-loaded while held | done | `hold_keys.rs` |
-| Hold any tool letter for a temporary tool | missing | #2672 |
+| Hold any tool letter for a temporary tool | done | `spring_tools.rs`: held ≥ 300 ms or used on the canvas, release gives the previous tool back; ⇧ never springs (#2672) |
| Scrubby zoom | done | `zoom_tool.rs` |
| Flick panning | done | `flick_pan.rs` (Preferences › Tools › Enable Flick Panning) |
| Animated zoom | missing | unread pref; #566 |
@@ -219,3 +219,4 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-11 | minor | ⇧-drag a guide out of a ruler lands on the nearest ruler tick (#3770) |
| 2026-10-11 | minor | Layer and selection keys from Photoshop's shortcut set: ⌘, toggles, ⌘\, /, ⌘⌥2, ⌘⌥⌫, Tab rename-next, ⌥-click thumbnail to fit |
| 2026-10-11 | minor | Tool keys from Photoshop's shortcut set: ← / → rotate the brush tip, ⇧-click for new type, Space+F canvas colour |
+| 2026-10-11 | minor | Spring-loaded tool letters done (#2672): holding any tool letter (Z included) past 300 ms, or using the canvas while it is down, makes the tool temporary until release |