replacing
This commit is contained in:
+15
-1
@@ -4,7 +4,12 @@ use crate::{app::App, cursor::Cursor};
|
||||
pub enum EditAction {
|
||||
Delete {
|
||||
cursor: Cursor,
|
||||
data: Vec<u8>
|
||||
old_data: Vec<u8>
|
||||
},
|
||||
Replace {
|
||||
cursor: Cursor,
|
||||
old_data: Vec<u8>,
|
||||
new_byte: u8
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +22,9 @@ impl App {
|
||||
fn execute_edit(&mut self, edit_action: &EditAction) {
|
||||
match edit_action {
|
||||
EditAction::Delete { cursor, .. } => self.delete_at(*cursor),
|
||||
EditAction::Replace {
|
||||
cursor, old_data: _, new_byte
|
||||
} => self.replace_at_with(*cursor, *new_byte),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +34,10 @@ impl App {
|
||||
self.cursor.head = min(cursor.head, cursor.tail);
|
||||
self.cursor.collapse();
|
||||
}
|
||||
|
||||
fn replace_at_with(&mut self, cursor: Cursor, new_byte: u8) {
|
||||
self.contents[self.cursor.range()].fill(new_byte);
|
||||
|
||||
self.cursor = cursor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user