Skip to content

Commit

Permalink
gap buffer p2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Jun 11, 2024
1 parent f9dfd8e commit 7a55b8d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/gap_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ impl GapBuffer {
}

fn move_cursor(&mut self, index: usize) {
if index < self.gap_start {}
if index < self.gap_start {
let move_size = self.gap_start - index;
self.buffer
.copy_within(index..self.gap_start, self.gap_end - move_size);
self.gap_start = index;
self.gap_end -= move_size;
} else if index > self.gap_start {
let move_size = index - self.gap_start;
self.buffer
.copy_within(self.gap_end..self.gap_end + move_size, self.gap_start);
self.gap_start += move_size;
self.gap_end += move_size;
}
}

fn to_string(&self) -> String {
let mut result: Vec<char> =
Vec::with_capacity(self.buffer.len() - (self.gap_end - self.gap_start));
}
}

0 comments on commit 7a55b8d

Please sign in to comment.