Fix panic on paste in TextInput after programmatic modification of contents
This commit is contained in:
parent
46ce3a1f00
commit
855c0faa59
@ -17,8 +17,10 @@ impl<'a> Editor<'a> {
|
|||||||
pub fn insert(&mut self, character: char) {
|
pub fn insert(&mut self, character: char) {
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection() {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
|
if left < self.value.len() {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(left, right);
|
self.value.remove_many(left, right.min(self.value.len()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
@ -32,8 +34,10 @@ impl<'a> Editor<'a> {
|
|||||||
|
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection() {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
|
if left < self.value.len() {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(left, right);
|
self.value.remove_many(left, right.min(self.value.len()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
@ -46,8 +50,10 @@ impl<'a> Editor<'a> {
|
|||||||
pub fn backspace(&mut self) {
|
pub fn backspace(&mut self) {
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection() {
|
||||||
Some((start, end)) => {
|
Some((start, end)) => {
|
||||||
|
if start < self.value.len() {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(start, end);
|
self.value.remove_many(start, end.min(self.value.len()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let start = self.cursor.start(self.value);
|
let start = self.cursor.start(self.value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user