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