Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Accept all-caps possessives in spell check (#8628)

NetterSilverc1158f92e812
diff --git a/crates/text/src/spell.rs b/crates/text/src/spell.rs
index 83576c899..bc2afa63c 100644
--- a/crates/text/src/spell.rs
+++ b/crates/text/src/spell.rs
@@ -88,7 +88,7 @@ impl Dictionary {
/// Whether `word` is spelled correctly (also accepting `user` words, compared without case).
pub fn check(&self, word: &str, user: &HashSet<String>) -> bool {
let w = normalize(word);
- let w = w.strip_suffix("'s").filter(|b| !b.is_empty()).unwrap_or(&w);
+ let w = w.strip_suffix("'s").or_else(|| w.strip_suffix("'S")).filter(|b| !b.is_empty()).unwrap_or(&w);
let w = w.trim_matches('\'');
if w.is_empty() || w.chars().any(|c| c.is_numeric()) || !w.chars().any(char::is_alphabetic) {
return true;
@@ -258,6 +258,15 @@ mod tests {
HashSet::new()
}
+ #[test]
+ fn all_caps_possessive_is_accepted() {
+ let d = Dictionary::english();
+ for w in ["MOTHER'S", "MONDAY'S", "Mother's", "mother's", "MOTHER’S"] {
+ assert!(d.check(w, &none()), "{w}");
+ }
+ assert!(!d.check("MOTHER'SX", &none()));
+ }
+
#[test]
fn bundled_dictionary_loads() {
let d = Dictionary::english();