Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Features
- [ ] 💻 Support for both desktop and web platform.
- [ ] 🤖 Support for the Rhai scripting language.
- [ ] 📝 Auto-suggestion / Auto-correction / Auto-completion.
- [ ] ☁️ Full immersion mode for non-latin languages. (🚧 Experimental 🚧)

Installation
===
Expand Down
4 changes: 0 additions & 4 deletions engine/preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ authors.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
inhibit = []
serde = ["dep:serde", "keyboard-types/serde"]

[dependencies]
keyboard-types = { version = "0.8.3", features = ["webdriver"] }
afrim-memory = { version = "0.4.2", path = "../../memory" }
serde = { version = "1.0.228", features = ["derive"], optional = true }

[dev-dependencies]
keyboard-types = { version = "0.8.3", features = ["webdriver"] }
1 change: 0 additions & 1 deletion engine/preprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ It generate a sequence of command to be perform to execute a particular task.

### Features

- inhibit: Enable the inhibit mode.
- serde: Enable serialization/deserialization.
211 changes: 0 additions & 211 deletions engine/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
//! });
//!
//! // Now let's look at the generated commands.
//! // The expected results without `inhibit` feature.
//! #[cfg(not(feature = "inhibit"))]
//! let mut expecteds = VecDeque::from(vec![
//! Command::Pause,
//! Command::Delete("c".to_string()),
Expand All @@ -42,26 +40,12 @@
//! Command::Resume,
//! ]);
//!
//! // The expected results with `inhibit` feature.
//! #[cfg(feature = "inhibit")]
//! let mut expecteds = VecDeque::from(vec![
//! Command::Pause,
//! Command::Delete("c".to_string()),
//! Command::Resume,
//! Command::Pause,
//! Command::Delete("c".to_string()),
//! Command::CommitText("ç".to_owned()),
//! Command::Resume,
//! ]);
//!
//! // Verification.
//! while let Some(command) = preprocessor.pop_queue() {
//! assert_eq!(command, expecteds.pop_front().unwrap());
//! }
//! assert_eq!(expecteds.is_empty(), true);
//! ```
//! **Note**: When dealing with non latin languages. The `inhibit` feature allows for the removal of
//! unwanted characters typically latin characters, as much as posssible.

mod message;

Expand Down Expand Up @@ -136,7 +120,6 @@ impl Preprocessor {

true
} else {
#[cfg(not(feature = "inhibit"))]
self.queue
.push_back(Command::Delete(_curr_char.to_string()));
self.cursor.resume();
Expand Down Expand Up @@ -190,8 +173,6 @@ impl Preprocessor {
/// assert_eq!(preprocessor.get_input(), "si3".to_owned());
///
/// // The generated commands.
/// // The expected results without inhibit feature.
/// #[cfg(not(feature = "inhibit"))]
/// let mut expecteds = VecDeque::from(vec![
/// Command::Pause,
/// Command::Delete("3".to_string()),
Expand All @@ -200,21 +181,6 @@ impl Preprocessor {
/// Command::Resume,
/// ]);
///
/// // The expected results with inhibit feature.
/// #[cfg(feature = "inhibit")]
/// let mut expecteds = VecDeque::from(vec![
/// Command::Pause,
/// Command::Delete("s".to_string()),
/// Command::Resume,
/// Command::Pause,
/// Command::Delete("i".to_string()),
/// Command::Resume,
/// Command::Pause,
/// Command::Delete("3".to_string()),
/// Command::CommitText("ī".to_owned()),
/// Command::Resume,
/// ]);
///
/// // Verification.
/// while let Some(command) = preprocessor.pop_queue() {
/// assert_eq!(command, expecteds.pop_front().unwrap());
Expand All @@ -226,14 +192,11 @@ impl Preprocessor {

match (event.state, event.key) {
(KeyState::Down, Key::Named(NamedKey::Backspace)) => {
#[cfg(not(feature = "inhibit"))]
{
self.pause();
committed = self.rollback();
self.resume();
}
#[cfg(feature = "inhibit")]
self.cursor.clear();
changed = true;
}
(KeyState::Down, Key::Character(character))
Expand All @@ -243,25 +206,17 @@ impl Preprocessor {
.map(|e| e.is_alphanumeric() || e.is_ascii_punctuation())
.unwrap_or(false) =>
{
#[cfg(feature = "inhibit")]
self.pause();
#[cfg(feature = "inhibit")]
self.queue.push_back(Command::Delete(character.clone()));

let character = character.chars().next().unwrap();

if let Some(_in) = self.cursor.hit(character) {
#[cfg(not(feature = "inhibit"))]
self.pause();
let mut prev_cursor = self.cursor.clone();
prev_cursor.undo();
#[cfg(not(feature = "inhibit"))]
self.queue.push_back(Command::Delete(character.to_string()));

// Remove the remaining code
while let (None, 1.., _c) = prev_cursor.state() {
prev_cursor.undo();
#[cfg(not(feature = "inhibit"))]
self.queue.push_back(Command::Delete(_c.to_string()));
}

Expand All @@ -270,13 +225,10 @@ impl Preprocessor {
}

self.queue.push_back(Command::CommitText(_in));
#[cfg(not(feature = "inhibit"))]
self.resume();
committed = true;
};

#[cfg(feature = "inhibit")]
self.resume();
changed = true;
}
(KeyState::Down, Key::Named(NamedKey::Shift) | Key::Named(NamedKey::CapsLock)) => (),
Expand Down Expand Up @@ -320,26 +272,13 @@ impl Preprocessor {
/// preprocessor.commit("sī".to_owned());
///
/// // The generated commands.
/// // The expected results without inhibit feature.
/// #[cfg(not(feature = "inhibit"))]
/// let mut expecteds = VecDeque::from(vec![
/// Command::Pause,
/// Command::Delete("s".to_string()),
/// Command::CommitText("sī".to_owned()),
/// Command::Resume,
/// ]);
///
/// // The expected results with inhibit feature.
/// #[cfg(feature = "inhibit")]
/// let mut expecteds = VecDeque::from(vec![
/// Command::Pause,
/// Command::Delete("s".to_string()),
/// Command::Resume,
/// Command::Pause,
/// Command::CommitText("sī".to_owned()),
/// Command::Resume,
/// ]);
///
/// // Verification.
/// while let Some(command) = preprocessor.pop_queue() {
/// assert_eq!(command, expecteds.pop_front().unwrap());
Expand All @@ -352,8 +291,6 @@ impl Preprocessor {
while !self.cursor.is_empty() {
self.rollback();
}
#[cfg(feature = "inhibit")]
self.cursor.clear();
self.queue.push_back(Command::CommitText(text));
self.resume();
// We clear the buffer
Expand Down Expand Up @@ -492,7 +429,6 @@ mod tests {
_ => unimplemented!(),
};
});
#[cfg(not(feature = "inhibit"))]
let mut expecteds = VecDeque::from(vec![
// c c
Command::Pause,
Expand All @@ -509,29 +445,6 @@ mod tests {
Command::CommitText("ç".to_owned()),
Command::Resume,
]);
#[cfg(feature = "inhibit")]
let mut expecteds = VecDeque::from(vec![
// c c
Command::Pause,
Command::Delete("c".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("c".to_string()),
Command::CommitText("ç".to_owned()),
Command::Resume,
// c e d
Command::Pause,
Command::Delete("c".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("e".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("d".to_string()),
Command::Delete("ç".to_string()),
Command::CommitText("ç".to_owned()),
Command::Resume,
]);

while let Some(command) = preprocessor.pop_queue() {
assert_eq!(command, expecteds.pop_front().unwrap());
Expand All @@ -551,10 +464,6 @@ mod tests {
let mut expecteds = VecDeque::from(vec![
Command::Pause,
Command::Delete("a".to_string()),
#[cfg(feature = "inhibit")]
Command::Resume,
#[cfg(feature = "inhibit")]
Command::Pause,
Command::CommitText("word".to_owned()),
Command::Resume,
]);
Expand Down Expand Up @@ -587,13 +496,10 @@ mod tests {
preprocessor.clear_queue();
assert_eq!(preprocessor.get_input(), "ccced".to_owned());
preprocessor.process(backspace_event.clone());
#[cfg(not(feature = "inhibit"))]
assert_eq!(preprocessor.get_input(), "cc".to_owned());
#[cfg(not(feature = "inhibit"))]
preprocessor.process(backspace_event);
assert_eq!(preprocessor.get_input(), "".to_owned());

#[cfg(not(feature = "inhibit"))]
let mut expecteds = VecDeque::from(vec![
Command::Pause,
Command::Delete("ç".to_string()),
Expand All @@ -604,10 +510,6 @@ mod tests {
Command::Resume,
]);

// NOTE: The inhibit feature don't support rollback
#[cfg(feature = "inhibit")]
let mut expecteds = VecDeque::from(vec![]);

while let Some(command) = preprocessor.pop_queue() {
assert_eq!(command, expecteds.pop_front().unwrap());
}
Expand All @@ -633,7 +535,6 @@ mod tests {
};
});

#[cfg(not(feature = "inhibit"))]
let mut expecteds = VecDeque::from(vec![
// Process
// u backspace
Expand Down Expand Up @@ -765,118 +666,6 @@ mod tests {
Command::Delete("\0".to_string()),
Command::Resume,
]);
#[cfg(feature = "inhibit")]
let mut expecteds = VecDeque::from(vec![
// Process
// u backspace
Command::Pause,
Command::Delete("u".to_string()),
Command::Resume,
// u u backspace
Command::Pause,
Command::Delete("u".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("u".to_string()),
Command::CommitText("ʉ".to_owned()),
Command::Resume,
// u
Command::Pause,
Command::Delete("u".to_string()),
Command::Resume,
// c _
Command::Pause,
Command::Delete("c".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("_".to_string()),
Command::CommitText("ç".to_owned()),
Command::Resume,
// c e d
Command::Pause,
Command::Delete("c".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("e".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("d".to_string()),
Command::Delete("ç".to_string()),
Command::CommitText("ç".to_owned()),
Command::Resume,
// u u
Command::Pause,
Command::Delete("u".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("u".to_string()),
Command::CommitText("ʉ".to_owned()),
Command::Resume,
// a f 3
Command::Pause,
Command::Delete("a".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("f".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("3".to_string()),
Command::Delete("ʉ".to_string()),
Command::CommitText("ʉ\u{304}ɑ\u{304}".to_owned()),
Command::Resume,
// a f
Command::Pause,
Command::Delete("a".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("f".to_string()),
Command::CommitText("ɑ".to_owned()),
Command::Resume,
// a f
Command::Pause,
Command::Delete("a".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("f".to_string()),
Command::CommitText("ɑ".to_owned()),
Command::Resume,
// a f
Command::Pause,
Command::Delete("a".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("f".to_string()),
Command::CommitText("ɑ".to_owned()),
Command::Resume,
// f
Command::Pause,
Command::Delete("f".to_string()),
Command::Delete("ɑ".to_string()),
Command::CommitText("ɑɑ".to_owned()),
Command::Resume,
// 3
Command::Pause,
Command::Delete("3".to_string()),
Command::Delete("ɑɑ".to_string()),
Command::CommitText("ɑ\u{304}ɑ\u{304}".to_owned()),
Command::Resume,
// uu
Command::Pause,
Command::Delete("u".to_string()),
Command::Resume,
Command::Pause,
Command::Delete("u".to_string()),
Command::CommitText("ʉ".to_owned()),
Command::Resume,
// 3
Command::Pause,
Command::Delete("3".to_string()),
Command::Delete("ʉ".to_owned()),
Command::CommitText("ʉ\u{304}".to_owned()),
Command::Resume,
// Rollback
// NOTE: The inhibit feature don't support rollback
]);

while let Some(command) = preprocessor.pop_queue() {
let c = expecteds.pop_front().unwrap();
Expand Down
Loading
Loading