Remove unnecessary borrows in Editor

This commit is contained in:
Héctor Ramón Jiménez 2020-03-25 14:07:32 +01:00
parent cb32326fe6
commit bc10ca501b

View File

@ -17,14 +17,14 @@ impl<'a> Editor<'a> {
pub fn insert(&mut self, character: char) {
match self.cursor.selection() {
Some((left, right)) => {
self.cursor.move_left(&self.value);
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => (),
}
self.value.insert(self.cursor.end(&self.value), character);
self.cursor.move_right(&self.value);
self.value.insert(self.cursor.end(self.value), character);
self.cursor.move_right(self.value);
}
pub fn paste(&mut self, content: Value) {
@ -32,29 +32,28 @@ impl<'a> Editor<'a> {
match self.cursor.selection() {
Some((left, right)) => {
self.cursor.move_left(&self.value);
self.cursor.move_left(self.value);
self.value.remove_many(left, right);
}
_ => (),
}
self.value
.insert_many(self.cursor.end(&self.value), content);
self.value.insert_many(self.cursor.end(self.value), content);
self.cursor.move_right_by_amount(&self.value, length);
self.cursor.move_right_by_amount(self.value, length);
}
pub fn backspace(&mut self) {
match self.cursor.selection() {
Some((start, end)) => {
self.cursor.move_left(&self.value);
self.cursor.move_left(self.value);
self.value.remove_many(start, end);
}
None => {
let start = self.cursor.start(&self.value);
let start = self.cursor.start(self.value);
if start > 0 {
self.cursor.move_left(&self.value);
self.cursor.move_left(self.value);
let _ = self.value.remove(start - 1);
}
@ -68,7 +67,7 @@ impl<'a> Editor<'a> {
self.backspace();
}
None => {
let end = self.cursor.end(&self.value);
let end = self.cursor.end(self.value);
if end < self.value.len() {
let _ = self.value.remove(end);