Skip to content

Commit

Permalink
feat(clafrica-lib): is_empty for function for the cursor
Browse files Browse the repository at this point in the history
This feature offer a proper way to know when the cursor is empty.
  • Loading branch information
pythonbrad committed Sep 15, 2023
1 parent 24744c9 commit 5526941
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clafrica-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ pub mod text_buffer {
pub fn clear(&mut self) {
self.buffer.clear();
}

/// Verify if the cursor is empty
pub fn is_empty(&self) -> bool {
return self.buffer.iter().filter(|c| c.key != '\0').count() == 0;
}
}
}

Expand Down Expand Up @@ -316,6 +321,7 @@ mod tests {
);
undo!(cursor 4);
assert_eq!(cursor.to_sequence(), vec!['\0', '\0']);
assert!(cursor.is_empty());
undo!(cursor 1);
assert_eq!(cursor.to_sequence(), vec![]);

Expand Down

0 comments on commit 5526941

Please sign in to comment.