From b7777144354837ce784cdb1887a9b584ff6c6e62 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 22 Jun 2022 04:42:05 +0800 Subject: [PATCH] modify textentry behavior: default text changes at the moment, default text will always come back if you remove the text so there is no text in the field (for example, you start typing, and then you decide you want to start over, the suggested text re-appears). this change makes it so that once you start typing, the suggested text does not return. Furthermore, it counts the initial backspace as a key that's hit, so you can clear the suggested text by just hitting backspace. --- services/gam/src/modal/textentry.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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();