Skip to content

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

Type: Space inserts a space while editing type (#4224)

Hevar Hemin2338492b1289
diff --git a/contributors/people.toml b/contributors/people.toml
index 9377474c8..fadd13984 100644
--- a/contributors/people.toml
+++ b/contributors/people.toml
@@ -133,3 +133,6 @@ sync_github_name = true
[people.lucAmbr0]
sync_github_name = true
+
+[people.Hevarh1]
+sync_github_name = true
diff --git a/crates/ui-egui/src/hold_keys.rs b/crates/ui-egui/src/hold_keys.rs
index c182247bf..3f2845cae 100644
--- a/crates/ui-egui/src/hold_keys.rs
+++ b/crates/ui-egui/src/hold_keys.rs
@@ -147,9 +147,10 @@ fn held(i: &InputState, sc: &KeyboardShortcut) -> bool {
}
/// The temporary tool whose key is held now, the most specific binding first (⌘Space before
-/// Space). Never while a text field has the keyboard.
+/// Space). Never while a text field has the keyboard, or while editing type on the canvas
+/// (Space must insert a space, not grab the Hand tool).
pub fn held_tool(app: &PhotocraftApp, ctx: &egui::Context) -> Option<Temporary> {
- if ctx.text_edit_focused() {
+ if ctx.text_edit_focused() || app.ui.text_edit.is_some() {
return None;
}
let count = |sc: &KeyboardShortcut| {
@@ -194,7 +195,7 @@ pub fn erase_held(app: &PhotocraftApp, ctx: &egui::Context) -> bool {
/// Is the reposition key (the Hand key, any modifiers) down?
pub fn reposition_held(app: &PhotocraftApp, ctx: &egui::Context) -> bool {
- !ctx.text_edit_focused() && binding(app, Temporary::Hand).is_some_and(|sc| ctx.input(|i| i.key_down(sc.logical_key)))
+ !ctx.text_edit_focused() && app.ui.text_edit.is_none() && binding(app, Temporary::Hand).is_some_and(|sc| ctx.input(|i| i.key_down(sc.logical_key)))
}
/// Tools whose in-progress drag the reposition key moves.
diff --git a/crates/ui-egui/src/hold_keys/tests.rs b/crates/ui-egui/src/hold_keys/tests.rs
index 45e806c64..d558a5a7b 100644
--- a/crates/ui-egui/src/hold_keys/tests.rs
+++ b/crates/ui-egui/src/hold_keys/tests.rs
@@ -174,6 +174,28 @@ fn space_is_a_temporary_hand_and_gives_the_tool_back() {
assert!(!st.session.active().unwrap().history.can_undo(), "nothing was painted");
}
+#[test]
+fn space_while_editing_type_is_not_the_hand_tool() {
+ let mut h = harness(Tool::Type);
+ let id = h.state_mut().run("type.create", json!({"text": "ئا", "size": 20, "x": 100, "y": 100})).unwrap()["layer"].as_u64().unwrap();
+ h.state_mut().ui.text_edit = Some(crate::state::TextEdit {
+ layer: id,
+ caret: 2,
+ anchor: 2,
+ session: "t".into(),
+ created: false,
+ mask: false,
+ dragging: false,
+ resize: None,
+ preedit: None,
+ });
+ key(&mut h, Key::Space, true, Modifiers::NONE);
+ assert!(h.state().ui.text_edit.is_some(), "type session stays open");
+ assert_eq!(held_tool(h.state(), &h.ctx), None, "Space types a space while editing");
+ assert!(!reposition_held(h.state(), &h.ctx));
+ key(&mut h, Key::Space, false, Modifiers::NONE);
+}
+
#[test]
fn temporary_zoom_in_and_out_restore_the_tool() {
let mut h = harness(Tool::RectMarquee);