mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
Merge pull request #19395
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
97ef03a68e
3 files changed
+101
No files matched your search
@@ -745,6 +745,10 @@ fn run_pressed(app: &mut PhotocraftApp, ctx: &egui::Context, f: &Fired) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The Eraser's Block mode ignores the brush size and hardness keys (#17695).
|
||||
if crate::eraser_ui::block_mode_ignores_key(app, id) {
|
||||
return;
|
||||
}
|
||||
if id == EditCommands::Delete.id() {
|
||||
// A finished work path shown by a Pen or Path Selection, or the path or segment Direct Selection targets:
|
||||
// ⌫/Delete edits the path, as in Photoshop (#5702, #12695, #13203), never Edit › Clear on the pixels under it.
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
//! #17695: with the Eraser in Block mode, `[`, `]`, ⇧[ and ⇧] change nothing, as in Photoshop: the stored tip keeps
|
||||
//! its size and hardness for Brush and Pencil mode, and no journal or history entry is added. In Brush and Pencil
|
||||
//! mode the keys step the tip as before. Driven through real key input on the whole app.
|
||||
|
||||
use egui::{Key, Modifiers};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::guide_cursor_tests::harness;
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The Eraser in `mode` with a 13 px, 100 % tip.
|
||||
fn eraser(mode: &str) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let mut h = harness(Tool::Eraser);
|
||||
h.state_mut().run("tools.setBrush", json!({"size": 13.0, "hardness": 1.0})).unwrap();
|
||||
h.state_mut().ui.tool_options.eraser_mode = mode.into();
|
||||
h.run_steps(2);
|
||||
h
|
||||
}
|
||||
|
||||
fn press(h: &mut Harness<'static, Box<PhotocraftApp>>, mods: Modifiers, key: Key) {
|
||||
h.key_press_modifiers(mods, key);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
/// The stored tip's size and hardness.
|
||||
fn tip(h: &Harness<'static, Box<PhotocraftApp>>) -> (f32, f32) {
|
||||
let brush = &h.state().session.tools.brush;
|
||||
(brush.size, brush.hardness)
|
||||
}
|
||||
|
||||
/// The journal length and the active document's undo steps.
|
||||
fn recorded(h: &Harness<'static, Box<PhotocraftApp>>) -> (usize, usize) {
|
||||
let app = h.state();
|
||||
(app.session.journal.len(), app.session.active().map_or(0, |st| st.history.past_len()))
|
||||
}
|
||||
|
||||
const KEYS: [(Modifiers, Key, &str); 4] = [
|
||||
(Modifiers::NONE, Key::CloseBracket, "]"),
|
||||
(Modifiers::NONE, Key::OpenBracket, "["),
|
||||
(Modifiers::SHIFT, Key::OpenBracket, "Shift+["),
|
||||
(Modifiers::SHIFT, Key::CloseBracket, "Shift+]"),
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn block_mode_bracket_keys_leave_the_stored_tip_and_record_nothing() {
|
||||
let mut h = eraser("block");
|
||||
let (before_tip, before_recorded) = (tip(&h), recorded(&h));
|
||||
assert_eq!(before_tip, (13.0, 1.0));
|
||||
for (mods, key, name) in KEYS {
|
||||
press(&mut h, mods, key);
|
||||
assert_eq!(tip(&h), before_tip, "{name} in Block mode keeps the stored size and hardness");
|
||||
assert_eq!(recorded(&h), before_recorded, "{name} in Block mode adds no journal or history entry");
|
||||
}
|
||||
// Back in Brush mode the tip is the one Block mode left alone.
|
||||
h.state_mut().ui.tool_options.eraser_mode = "brush".into();
|
||||
h.run_steps(2);
|
||||
assert_eq!(tip(&h), (13.0, 1.0), "Brush mode finds the 13 px, 100 % tip");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn brush_and_pencil_mode_keys_still_step_the_tip() {
|
||||
for mode in ["brush", "pencil"] {
|
||||
let mut h = eraser(mode);
|
||||
press(&mut h, Modifiers::NONE, Key::CloseBracket);
|
||||
assert_eq!(tip(&h).0, 15.0, "{mode}: ] grows 13 px to 15 px");
|
||||
press(&mut h, Modifiers::NONE, Key::OpenBracket);
|
||||
assert_eq!(tip(&h).0, 10.0, "{mode}: [ shrinks 15 px to 10 px");
|
||||
press(&mut h, Modifiers::SHIFT, Key::OpenBracket);
|
||||
assert_eq!(tip(&h).1, 0.75, "{mode}: Shift+[ softens 100 % to 75 %");
|
||||
press(&mut h, Modifiers::SHIFT, Key::CloseBracket);
|
||||
assert_eq!(tip(&h).1, 1.0, "{mode}: Shift+] hardens 75 % to 100 %");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_tools_keep_their_keys_with_the_eraser_mode_set_to_block() {
|
||||
let mut h = harness(Tool::Brush);
|
||||
h.state_mut().run("tools.setBrush", json!({"size": 13.0, "hardness": 1.0})).unwrap();
|
||||
h.state_mut().ui.tool_options.eraser_mode = "block".into();
|
||||
h.run_steps(2);
|
||||
press(&mut h, Modifiers::NONE, Key::CloseBracket);
|
||||
assert_eq!(tip(&h).0, 15.0, "the Brush's ] still grows the tip");
|
||||
}
|
||||
@@ -135,6 +135,14 @@ pub fn block_mode(app: &PhotocraftApp, tool: Tool) -> bool {
|
||||
tool == Tool::Eraser && app.ui.tool_options.eraser_mode == "block"
|
||||
}
|
||||
|
||||
/// Whether the fired command `id` is a brush size or hardness key (`[`, `]`, ⇧[, ⇧]) that the Eraser in Block mode
|
||||
/// ignores, as in Photoshop: the block is 16 screen pixels whatever the tip, so the keys change nothing and leave the
|
||||
/// stored tip for Brush and Pencil mode, with no journal or history entry (#17695).
|
||||
pub(crate) fn block_mode_ignores_key(app: &PhotocraftApp, id: &str) -> bool {
|
||||
block_mode(app, app.ui.tool)
|
||||
&& matches!(id, "tools.decreaseBrushSize" | "tools.increaseBrushSize" | "tools.decreaseBrushHardness" | "tools.increaseBrushHardness")
|
||||
}
|
||||
|
||||
/// The Block's edge in document pixels at the current zoom (what the engine erases).
|
||||
pub fn block_size(app: &PhotocraftApp) -> f32 {
|
||||
photocraft_engine::brush_cmds::block_size(f64::from(app.point_zoom()))
|
||||
@@ -341,3 +349,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "eraser_block_mode_keys_tests.rs"]
|
||||
mod eraser_block_mode_keys_tests;
|
||||
Reference in new issue
Block a user