Merge pull request #445 from mtkennerly/bugfix/paste-panic
Fix panic on paste in TextInput after programmatic modification of contents
This commit is contained in:
commit
62ec03a0af
@ -329,7 +329,7 @@ where
|
|||||||
}
|
}
|
||||||
keyboard::KeyCode::Backspace => {
|
keyboard::KeyCode::Backspace => {
|
||||||
if platform::is_jump_modifier_pressed(modifiers)
|
if platform::is_jump_modifier_pressed(modifiers)
|
||||||
&& self.state.cursor.selection().is_none()
|
&& self.state.cursor.selection(&self.value).is_none()
|
||||||
{
|
{
|
||||||
if self.is_secure {
|
if self.is_secure {
|
||||||
let cursor_pos = self.state.cursor.end(&self.value);
|
let cursor_pos = self.state.cursor.end(&self.value);
|
||||||
@ -349,7 +349,7 @@ where
|
|||||||
}
|
}
|
||||||
keyboard::KeyCode::Delete => {
|
keyboard::KeyCode::Delete => {
|
||||||
if platform::is_jump_modifier_pressed(modifiers)
|
if platform::is_jump_modifier_pressed(modifiers)
|
||||||
&& self.state.cursor.selection().is_none()
|
&& self.state.cursor.selection(&self.value).is_none()
|
||||||
{
|
{
|
||||||
if self.is_secure {
|
if self.is_secure {
|
||||||
let cursor_pos = self.state.cursor.end(&self.value);
|
let cursor_pos = self.state.cursor.end(&self.value);
|
||||||
|
@ -166,8 +166,8 @@ impl Cursor {
|
|||||||
end.min(value.len())
|
end.min(value.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn selection(&self) -> Option<(usize, usize)> {
|
pub(crate) fn selection(&self, value: &Value) -> Option<(usize, usize)> {
|
||||||
match self.state {
|
match self.state(value) {
|
||||||
State::Selection { start, end } => {
|
State::Selection { start, end } => {
|
||||||
Some((start.min(end), start.max(end)))
|
Some((start.min(end), start.max(end)))
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ 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(self.value) {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(left, right);
|
self.value.remove_many(left, right);
|
||||||
@ -30,7 +30,7 @@ impl<'a> Editor<'a> {
|
|||||||
pub fn paste(&mut self, content: Value) {
|
pub fn paste(&mut self, content: Value) {
|
||||||
let length = content.len();
|
let length = content.len();
|
||||||
|
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection(self.value) {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(left, right);
|
self.value.remove_many(left, right);
|
||||||
@ -44,7 +44,7 @@ impl<'a> Editor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn backspace(&mut self) {
|
pub fn backspace(&mut self) {
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection(self.value) {
|
||||||
Some((start, end)) => {
|
Some((start, end)) => {
|
||||||
self.cursor.move_left(self.value);
|
self.cursor.move_left(self.value);
|
||||||
self.value.remove_many(start, end);
|
self.value.remove_many(start, end);
|
||||||
@ -61,7 +61,7 @@ impl<'a> Editor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&mut self) {
|
pub fn delete(&mut self) {
|
||||||
match self.cursor.selection() {
|
match self.cursor.selection(self.value) {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
self.backspace();
|
self.backspace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user