diff --git a/services/gam/src/modal/textentry.rs b/services/gam/src/modal/textentry.rs index 9f6d3f4dd..662fd387a 100644 --- a/services/gam/src/modal/textentry.rs +++ b/services/gam/src/modal/textentry.rs @@ -52,6 +52,9 @@ pub struct TextEntry { max_field_amount: u32, selected_field: i16, field_height: Cell::, + /// track if keys were hit since initialized: this allows us to clear the default text, + /// instead of having it re-appear every time the text area is cleared + keys_hit: bool, } impl Default for TextEntry { @@ -66,6 +69,7 @@ impl Default for TextEntry { action_payloads: Default::default(), max_field_amount: 0, field_height: Cell::new(0), + keys_hit: false, } } } @@ -105,6 +109,7 @@ impl TextEntry { self.action_payloads = payload; self.max_field_amount = fields; + self.keys_hit = false; } } @@ -194,7 +199,7 @@ impl ActionApi for TextEntry { tv.style = if self.is_password { GlyphStyle::Monospace } else { - if payload.placeholder.is_some() && payload.content.len().is_zero() { + if payload.placeholder.is_some() && payload.content.len().is_zero() && self.keys_hit { // note: this is just a "recommendation" - if there is an emoji or chinese character in this string, the height revers to modal.style's height GlyphStyle::Small } else { @@ -210,7 +215,7 @@ impl ActionApi for TextEntry { match self.visibility { TextEntryVisibility::Visible => { let content = { - if payload.placeholder.is_some() && payload.content.len().is_zero() { + if payload.placeholder.is_some() && payload.content.len().is_zero() && !self.keys_hit { let placeholder_content = payload.placeholder.unwrap(); placeholder_content.to_string() } else { @@ -389,6 +394,11 @@ impl ActionApi for TextEntry { } }, '∴' | '\u{d}' => { + if payload.content.len() == 0 && !self.keys_hit { + if let Some(placeholder) = payload.placeholder { + payload.content.append(placeholder.to_str()).ok(); + } + } if let Some(validator) = self.validator { if let Some(err_msg) = validator(*payload, self.action_opcode) { payload.content.clear(); // reset the input field @@ -405,6 +415,7 @@ impl ActionApi for TextEntry { for payload in self.action_payloads.iter_mut() { payload.volatile_clear(); } + self.keys_hit = false; return (None, true) } @@ -422,6 +433,7 @@ impl ActionApi for TextEntry { // ignore null messages } '\u{8}' => { // backspace + self.keys_hit = true; #[cfg(feature="tts")] { let xns = xous_names::XousNames::new().unwrap(); @@ -441,6 +453,7 @@ impl ActionApi for TextEntry { } } _ => { // text entry + self.keys_hit = true; #[cfg(feature="tts")] { let xns = xous_names::XousNames::new().unwrap();