Skip to content

Commit

Permalink
Merge f10d101 into b535125
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Aug 27, 2023
2 parents b535125 + f10d101 commit 7353608
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion clafrica-lib/data/sample.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
x y
2a_ á̠
2aa áá
2af_ ɑ̠́
Expand All @@ -11,4 +12,4 @@
2oo óó
2ua úá
2uaf úɑ́
2uuaf ʉ́ɑ́
2uuaf ʉ́ɑ́
29 changes: 19 additions & 10 deletions clafrica-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub mod text_buffer {
.buffer
.iter()
.last()
.unwrap_or(&self.root)
.unwrap_or(&Rc::new(Node::new('\0', 0)))
.goto(character)
.or_else(|| {
// We end the current sequence
Expand Down Expand Up @@ -187,6 +187,7 @@ pub mod utils {
pub fn load_data(file_path: &str) -> Result<Vec<Vec<String>>, io::Error> {
let data = fs::read_to_string(file_path)?;
let data = data
.trim()
.split('\n')
.map(|line| {
line.split_whitespace()
Expand Down Expand Up @@ -285,41 +286,49 @@ mod tests {
.collect(),
);

let mut cursor = text_buffer::Cursor::new(root, 5);
let mut cursor = text_buffer::Cursor::new(root, 8);

assert_eq!(cursor.state(), (None, 0, '\0'));

hit!(cursor '2', 'i', 'a', 'f');
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'a', 'f']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'a', 'f']);

assert_eq!(cursor.state(), (Some("íɑ́".to_owned()), 4, 'f'));

undo!(cursor 1);
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'a']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'a']);

undo!(cursor 1);
cursor.hit('e');
assert_eq!(cursor.to_sequence(), vec!['2', 'i', 'e']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'i', 'e']);

undo!(cursor 2);
hit!(cursor 'o', 'o');
assert_eq!(cursor.to_sequence(), vec!['2', 'o', 'o']);
assert_eq!(cursor.to_sequence(), vec!['\0', '2', 'o', 'o']);

undo!(cursor 3);
assert_eq!(cursor.to_sequence(), vec![]);
assert_eq!(cursor.to_sequence(), vec!['\0']);

hit!(cursor '2', '2', 'u', 'a');
assert_eq!(cursor.to_sequence(), vec!['2', '\0', '2', 'u', 'a']);
assert_eq!(
cursor.to_sequence(),
vec!['\0', '\0', '2', '\0', '2', 'u', 'a']
);
undo!(cursor 4);
assert_eq!(cursor.to_sequence(), vec!['\0', '\0']);
undo!(cursor 1);
assert_eq!(cursor.to_sequence(), vec![]);

hit!(
cursor
'a', 'a', '2', 'a', 'e', 'a', '2', 'f', 'a',
'2', '2', '2', 'i', 'a', '2', '2', '_', 'f',
'2', '2', 'x', 'x', '2', 'i', 'a', '2', '2', '_', 'f',
'2', 'a', '2', 'a', '_'
);
assert_eq!(cursor.to_sequence(), vec!['a', '\0', '2', 'a', '_']);
assert_eq!(
cursor.to_sequence(),
vec!['f', '\0', '2', 'a', '\0', '2', 'a', '_']
);

cursor.clear();
assert_eq!(cursor.to_sequence(), vec![]);
Expand Down
4 changes: 3 additions & 1 deletion clafrica/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ impl Processor {
}
EventType::KeyPress(_) => {
let character = character.unwrap();
let mut prev_cursor = self.cursor.clone();

if let Some(_in) = self.cursor.hit(character) {
self.pause();

let mut prev_cursor = self.cursor.clone();
prev_cursor.undo();
self.keyboard.key_click(Key::Backspace);

// Remove the remaining code
Expand Down

0 comments on commit 7353608

Please sign in to comment.