Skip to content

Commit

Permalink
Fixed issue #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthoerner committed Feb 2, 2023
1 parent 2fc65ba commit 657fc88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Buffer {
// Get the current cursor coordinate from a given buffer index
pub fn cursor_coord(&self, index: usize) -> Option<(u16, u16)> {
// Make sure the index is valid
if index >= self.rope.len_chars() {
if index > self.size() {
return None;
}

Expand All @@ -77,7 +77,8 @@ impl Buffer {
}
}

unreachable!("[INTERNAL ERROR] The given index was out of bounds but was not caught by the guard clause")
// If the index is at the end of the buffer, return the last coordinate
Some(((index - current_line_start) as u16, current_line as u16))
}

// Get the number of characters in the buffer
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl CursorPosition {

// Moves the cursor right
pub fn move_right(&mut self, buffer: &Buffer) {
if self.buffer_index < buffer.size() - 1 {
if self.buffer_index < buffer.size() {
self.buffer_index += 1;
}

Expand Down

0 comments on commit 657fc88

Please sign in to comment.