From 731e6752eb2130fb4ff2b92fd9c3274ea1b3110d Mon Sep 17 00:00:00 2001 From: FabianLars Date: Fri, 13 Mar 2020 17:54:02 +0100 Subject: keep cursor inside value boundaries more reliable --- native/src/widget/text_input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 68fd7dfb..82406b5a 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -324,7 +324,7 @@ where } _ => (), } - self.value.insert(self.state.cursor.end(), c); + self.value.insert(self.state.cursor.end().min(self.value.len()), c); self.state.cursor.move_right(&self.value); let message = (self.on_change)(self.value.to_string()); @@ -347,11 +347,11 @@ where self.state.cursor.move_left(); } None => { - if self.state.cursor.start() > 0 { + if self.state.cursor.start().min(self.value.len()) > 0 { self.state.cursor.move_left(); let _ = self .value - .remove(self.state.cursor.start() - 1); + .remove(self.state.cursor.start()); } } } -- cgit