replacing

This commit is contained in:
alice pellerin
2026-03-18 14:46:04 -05:00
parent bfc67a2671
commit ba3d80f111
7 changed files with 114 additions and 44 deletions
+15 -1
View File
@@ -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;
}
}