diff options
author | 2020-07-11 00:25:47 +0200 | |
---|---|---|
committer | 2020-07-11 00:25:47 +0200 | |
commit | 62ec03a0afe8566a8f0b06675990a83fd65de1a9 (patch) | |
tree | b7d7e1a7ec15171a130e41c5c2c17e27b10432d1 /native/src/widget/text_input | |
parent | 46ce3a1f0004ddc527ba3de1ffe3dac3f41a06c3 (diff) | |
parent | 4314ce36f4242398a3228defc70e056e1e87f175 (diff) | |
download | iced-62ec03a0afe8566a8f0b06675990a83fd65de1a9.tar.gz iced-62ec03a0afe8566a8f0b06675990a83fd65de1a9.tar.bz2 iced-62ec03a0afe8566a8f0b06675990a83fd65de1a9.zip |
Merge pull request #445 from mtkennerly/bugfix/paste-panic
Fix panic on paste in TextInput after programmatic modification of contents
Diffstat (limited to 'native/src/widget/text_input')
-rw-r--r-- | native/src/widget/text_input/cursor.rs | 4 | ||||
-rw-r--r-- | native/src/widget/text_input/editor.rs | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/native/src/widget/text_input/cursor.rs b/native/src/widget/text_input/cursor.rs index 16e7a01b..aa03bb74 100644 --- a/native/src/widget/text_input/cursor.rs +++ b/native/src/widget/text_input/cursor.rs @@ -166,8 +166,8 @@ impl Cursor { end.min(value.len()) } - pub(crate) fn selection(&self) -> Option<(usize, usize)> { - match self.state { + pub(crate) fn selection(&self, value: &Value) -> Option<(usize, usize)> { + match self.state(value) { State::Selection { start, end } => { Some((start.min(end), start.max(end))) } diff --git a/native/src/widget/text_input/editor.rs b/native/src/widget/text_input/editor.rs index c9b9795d..20e42567 100644 --- a/native/src/widget/text_input/editor.rs +++ b/native/src/widget/text_input/editor.rs @@ -15,7 +15,7 @@ impl<'a> Editor<'a> { } pub fn insert(&mut self, character: char) { - match self.cursor.selection() { + match self.cursor.selection(self.value) { Some((left, right)) => { self.cursor.move_left(self.value); self.value.remove_many(left, right); @@ -30,7 +30,7 @@ impl<'a> Editor<'a> { pub fn paste(&mut self, content: Value) { let length = content.len(); - match self.cursor.selection() { + match self.cursor.selection(self.value) { Some((left, right)) => { self.cursor.move_left(self.value); self.value.remove_many(left, right); @@ -44,7 +44,7 @@ impl<'a> Editor<'a> { } pub fn backspace(&mut self) { - match self.cursor.selection() { + match self.cursor.selection(self.value) { Some((start, end)) => { self.cursor.move_left(self.value); self.value.remove_many(start, end); @@ -61,7 +61,7 @@ impl<'a> Editor<'a> { } pub fn delete(&mut self) { - match self.cursor.selection() { + match self.cursor.selection(self.value) { Some(_) => { self.backspace(); } |