summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-21 05:49:09 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-21 05:49:09 +0100
commitc04dff99da3c524de6885d3f1ce13b5e24cf5e57 (patch)
treed686f2e738da6d02048a4539c4b6d303e173906e /native
parent938177e22554ec136b85347a373d6d7ac195030e (diff)
downloadiced-c04dff99da3c524de6885d3f1ce13b5e24cf5e57.tar.gz
iced-c04dff99da3c524de6885d3f1ce13b5e24cf5e57.tar.bz2
iced-c04dff99da3c524de6885d3f1ce13b5e24cf5e57.zip
Fix sneaky overflow in `TextInput` when pasting
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/text_input.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index a6ddeb5c..1d1c32a2 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -310,7 +310,10 @@ where
self.value
.insert_many(cursor_position, content.clone());
- self.state.cursor_position += content.len();
+ self.state.move_cursor_right_by_amount(
+ &self.value,
+ content.len(),
+ );
self.state.is_pasting = Some(content);
let message =
@@ -461,6 +464,7 @@ pub struct State {
is_focused: bool,
is_pasting: Option<Value>,
cursor_position: usize,
+ // TODO: Add stateful horizontal scrolling offset
}
impl State {
@@ -513,10 +517,19 @@ impl State {
///
/// [`TextInput`]: struct.TextInput.html
pub(crate) fn move_cursor_right(&mut self, value: &Value) {
+ self.move_cursor_right_by_amount(value, 1)
+ }
+
+ pub(crate) fn move_cursor_right_by_amount(
+ &mut self,
+ value: &Value,
+ amount: usize,
+ ) {
let current = self.cursor_position(value);
+ let new_position = current.saturating_add(amount);
- if current < value.len() {
- self.cursor_position = current + 1;
+ if new_position < value.len() + 1 {
+ self.cursor_position = new_position;
}
}