mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #11521: Shift+letter cycles a tool group in toolbar order and the anchor point tools no longer take the letter P (#11376)
This commit is contained in:
commit
45c797b85b
8 files changed
+188
-13
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,12 @@ 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 (the cycle and the fallback to the group's first tool) uses the toolbar
|
||||
// flyout's order; plain keys keep the `Tool::ALL` order.
|
||||
if cycle_shift {
|
||||
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()],
|
||||
|
||||
@@ -798,6 +798,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)]
|
||||
mod toolbar_group_order_tests;
|
||||
|
||||
@@ -51,6 +51,12 @@ pub(crate) 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(), ' | ||||