summaryrefslogtreecommitdiffstats
path: root/native/src/widget
diff options
context:
space:
mode:
authorLibravatar FabianLars <fabianlars@fabianlars.de>2020-03-13 17:54:02 +0100
committerLibravatar FabianLars <fabianlars@fabianlars.de>2020-03-13 17:54:02 +0100
commit731e6752eb2130fb4ff2b92fd9c3274ea1b3110d (patch)
treeb874136755d476624fe7442b0f0112519e3539cc /native/src/widget
parent767096b9bbe091f6fed2a3ff31a4c6cc1131ecea (diff)
downloadiced-731e6752eb2130fb4ff2b92fd9c3274ea1b3110d.tar.gz
iced-731e6752eb2130fb4ff2b92fd9c3274ea1b3110d.tar.bz2
iced-731e6752eb2130fb4ff2b92fd9c3274ea1b3110d.zip
keep cursor inside value boundaries more reliable
Diffstat (limited to 'native/src/widget')
-rw-r--r--native/src/widget/text_input.rs6
1 files changed, 3 insertions, 3 deletions
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());
}
}
}