mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Shift+letter cycles a tool group in toolbar order and the anchor point tools no longer take the letter P (#11376)
The group Shift+letter steps through is now sorted by position in TOOL_SECTIONS, so it follows the flyout instead of Tool::ALL. Add Anchor Point, Delete Anchor Point and Convert Point have no default letter, so P cycles only Pen, Freeform Pen and Curvature Pen. The engine's shortcut table lists the three anchor point tools without a key to match, and two tests that expected the letter P for them are updated. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
405b56c3c2
commit
8d33de79b0
9 files changed
+151
-15
No files matched your search
@@ -157,9 +157,9 @@ pub const TOOLS: &[(&str, &str, Option<&str>)] = &[
|
||||
("tools.select.pen", "Pen Tool", Some("P")),
|
||||
("tools.select.freeformPen", "Freeform Pen Tool", Some("P")),
|
||||
("tools.select.curvaturePen", "Curvature Pen Tool", Some("P")),
|
||||
("tools.select.addAnchorPoint", "Add Anchor Point Tool", Some("P")),
|
||||
("tools.select.deleteAnchorPoint", "Delete Anchor Point Tool", Some("P")),
|
||||
("tools.select.convertPoint", "Convert Point Tool", Some("P")),
|
||||
("tools.select.addAnchorPoint", "Add Anchor Point Tool", None),
|
||||
("tools.select.deleteAnchorPoint", "Delete Anchor Point Tool", None),
|
||||
("tools.select.convertPoint", "Convert Point Tool", None),
|
||||
("tools.select.pathSelection", "Path Selection Tool", Some("A")),
|
||||
("tools.select.directSelection", "Direct Selection Tool", Some("A")),
|
||||
("tools.select.rectangle", "Rectangle Tool", Some("U")),
|
||||
|
||||
@@ -905,7 +905,9 @@ fn select_tool_by_key(app: &mut PhotocraftApp, ctx: &egui::Context, pressed: &im
|
||||
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() && crate::tool_shortcuts::uses_default(app, *x)).collect();
|
||||
let mut group: Vec<Tool> = Tool::ALL.iter().copied().filter(|x| x.key() == t.key() && crate::tool_shortcuts::uses_default(app, *x)).collect();
|
||||
// Shift+key steps in the toolbar flyout's order, not the order of `Tool::ALL`.
|
||||
group.sort_by_key(|x| crate::panels::toolbar::toolbar_position(*x));
|
||||
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()],
|
||||
|
||||
@@ -791,6 +791,8 @@ mod pencil_tests;
|
||||
#[cfg(test)]
|
||||
mod tool_options_theme_tests;
|
||||
#[cfg(test)]
|
||||
mod tool_shift_cycle_order_tests;
|
||||
#[cfg(test)]
|
||||
mod tool_shortcut_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -60,7 +60,7 @@ pub mod swatches_ui;
|
||||
pub(super) mod timeline_ui;
|
||||
pub(crate) mod title_bar;
|
||||
pub(super) mod titlebar;
|
||||
mod toolbar;
|
||||
pub(crate) mod toolbar;
|
||||
pub mod type_panels_ui;
|
||||
pub(super) mod variables_ui;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{Align2, Color32, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKin
|
||||
/// Tool groups separated by hairlines, Photoshop order.
|
||||
/// Photoshop toolbar: divider-separated sections of slots; each slot is a flyout group whose button
|
||||
/// shows the group's last-used tool.
|
||||
pub(super) const TOOL_SECTIONS: &[&[&[Tool]]] = &[
|
||||
pub(crate) const TOOL_SECTIONS: &[&[&[Tool]]] = &[
|
||||
&[&[Tool::Move, Tool::Artboard]],
|
||||
&[
|
||||
&[Tool::RectMarquee, Tool::EllipseMarquee, Tool::SingleRowMarquee, Tool::SingleColumnMarquee],
|
||||
@@ -51,6 +51,12 @@ pub(super) fn next_slot_tool(slot: &[Tool], from: Tool) -> Tool {
|
||||
i.checked_add(1).and_then(|n| n.checked_rem(slot.len())).and_then(|n| slot.get(n)).copied().unwrap_or(from)
|
||||
}
|
||||
|
||||
/// Position of `tool` in [`TOOL_SECTIONS`] read top to bottom, slot by slot. Tools outside the
|
||||
/// toolbar sort last. Shift+letter orders a key's group by this so it steps like the flyout.
|
||||
pub(crate) fn toolbar_position(tool: Tool) -> usize {
|
||||
TOOL_SECTIONS.iter().flat_map(|section| section.iter()).flat_map(|slot| slot.iter()).position(|&t| t == tool).unwrap_or(usize::MAX)
|
||||
}
|
||||
|
||||
/// [`TOOL_SECTIONS`] without the tools hidden in Edit › Toolbar (`hidden` holds tool names: the
|
||||
/// dialog writes `Tool` debug names, `edit.toolbar` takes any name `Tool::from_name` reads). A
|
||||
/// slot keeps only its visible tools, so its flyout lists just those; a slot with none left is
|
||||
|
||||
@@ -739,10 +739,10 @@ mod tests {
|
||||
assert_eq!(Tool::from_name("Vertical Type Mask Tool"), Some(Tool::VerticalTypeMask));
|
||||
assert_eq!(Tool::from_name("addAnchorPoint"), Some(Tool::AddAnchorPoint));
|
||||
assert_eq!(Tool::from_name("Delete Anchor Point Tool"), Some(Tool::DeleteAnchorPoint));
|
||||
assert_eq!(Tool::DeleteAnchorPoint.key(), 'P');
|
||||
assert_eq!(Tool::DeleteAnchorPoint.key(), ' | ||||