mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Tool keys look through the list for the last tool they can still pick
This commit is contained in:
1 parent
75df80fe33
commit
8f2b952359
3 files changed
+16
-1
No files matched your search
@@ -909,7 +909,7 @@ fn select_tool_by_key(app: &mut PhotocraftApp, ctx: &egui::Context, pressed: &im
|
||||
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()).filter(|last| group.contains(last)).unwrap_or(group[0]),
|
||||
None => app.ui.group_tools.iter().copied().find(|last| group.contains(last)).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));
|
||||
|
||||
@@ -72,6 +72,20 @@ fn shift_key_tool_switch_is_the_default() {
|
||||
assert_ne!(app.ui.tool, Tool::Type);
|
||||
}
|
||||
|
||||
/// A tool with a shortcut of its own leaves its letter (#4086) but stays in the history: the letter
|
||||
/// falls back on the last tool it still picks, not on its group's first.
|
||||
#[test]
|
||||
fn a_tool_key_passes_over_a_remapped_tool_to_the_last_one_it_picks() {
|
||||
use crate::state::Tool;
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
app.run("prefs.set", json!({"path": "shortcuts.tools.select.polygonLasso", "value": "F6"})).unwrap();
|
||||
app.ui.remember_group_tool(Tool::MagneticLasso);
|
||||
app.ui.remember_group_tool(Tool::PolygonLasso);
|
||||
press_key(&mut app, &ctx, Key::L, Modifiers::NONE);
|
||||
assert_eq!(app.ui.tool, Tool::MagneticLasso);
|
||||
}
|
||||
|
||||
/// #3109: on a German layout Ö / # (physical `;` / `\`) step the brush size and ⇧Ö / ⇧#
|
||||
/// (⇧# types `'`) its hardness, as Photoshop's German shortcuts.
|
||||
#[test]
|
||||
|
||||
@@ -656,6 +656,7 @@ impl UiState {
|
||||
}
|
||||
|
||||
/// The last tool used in the shortcut group of `key`, if any.
|
||||
#[cfg(test)]
|
||||
pub fn group_tool(&self, key: char) -> Option<Tool> {
|
||||
self.group_tools.iter().copied().find(|t| t.key() == key)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user