From 3e5936e9207251024046ef0e1543dae2298697e0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 10 Mar 2021 02:05:31 +0800 Subject: [PATCH] fix backspace edge case --- services/ime-frontend/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/ime-frontend/src/main.rs b/services/ime-frontend/src/main.rs index fdb8702ae..8f026a82a 100644 --- a/services/ime-frontend/src/main.rs +++ b/services/ime-frontend/src/main.rs @@ -213,7 +213,7 @@ impl InputTracker { } pub fn update(&mut self, newkeys: [char; 4]) -> Result>, xous::Error> { - let debug1= false; + let debug1= true; let mut update_predictor = false; let mut retstring: Option> = None; if let Some(ic) = self.input_canvas { @@ -285,6 +285,7 @@ impl InputTracker { } '\u{0008}' => { // backspace if (self.characters > 0) && (self.insertion == self.characters) { + if debug1{info!("IMEF: simple backspace case")} self.line.pop(); self.characters -= 1; self.insertion -= 1; @@ -299,6 +300,7 @@ impl InputTracker { self.pred_phrase.clear(); } } else if (self.characters > 0) && (self.insertion > 0) { + if debug1{info!("IMEF: mid-string backspace case")} // awful O(N) algo because we have to decode variable-length utf8 strings to figure out character boundaries // first, make a copy of the string let tempbytes: [u8; 4000] = self.line.as_bytes(); @@ -456,7 +458,7 @@ impl InputTracker { if debug1{info!("IMEF: got computed cursor of {:?}", input_tv.cursor);} // check if the cursor is now at the bottom of the textview, this means we need to grow the box - if input_tv.cursor.line_height == 0 { + if input_tv.cursor.line_height == 0 && self.characters > 0 { if debug1{info!("IMEF: caught case of overflowed text box, attempting to resize");} let delta = if self.last_height > 0 { self.last_height + 1 + 1 // 1 pixel allowance for interline space, plus 1 for fencepost