mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-08 19:42:12 +00:00
Proofing: a hyphenated word added to the dictionary is no longer flagged (fixes storytold/wordcraft#2082) (storytold/wordcraft#2085)
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
1 parent
de00c8a16a
commit
2d5fb1279a
2 files changed
+15
-2
No files matched your search
@@ -407,14 +407,17 @@ pub fn is_correct(word: &str) -> bool {
|
||||
}
|
||||
|
||||
/// The words every language's check accepts under `opts`: single letters, words without
|
||||
/// letters, words with digits (Ignore words that contain numbers) and words in capitals
|
||||
/// (Ignore words in UPPERCASE).
|
||||
/// letters, words with digits (Ignore words that contain numbers), words in capitals
|
||||
/// (Ignore words in UPPERCASE) and words in the user dictionary.
|
||||
fn accepted_by_options(word: &str, opts: &Options) -> bool {
|
||||
let w = word.trim_matches(|c: char| !c.is_alphanumeric() && c != '\'').trim_matches('\'');
|
||||
w.chars().count() <= 1
|
||||
|| !w.chars().any(char::is_alphabetic)
|
||||
|| (opts.ignore_numbers && w.chars().any(|c| c.is_ascii_digit()))
|
||||
|| (opts.ignore_uppercase && w.chars().all(|c| !c.is_lowercase()))
|
||||
// The whole word: the languages split a hyphenated word into its parts, and an added
|
||||
// `Unigranrio-RJ` is none of them (#2082).
|
||||
|| in_user_dictionary(&w.to_lowercase())
|
||||
}
|
||||
|
||||
/// [`is_correct`] with the File › Options › Proofing choices.
|
||||
|
||||
@@ -206,4 +206,14 @@ mod tests {
|
||||
crate::add_word("Zxqportuguespalavra");
|
||||
assert!(is_correct("zxqportuguespalavra"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_dictionary_accepts_a_hyphenated_word_whole() {
|
||||
test_dict::install();
|
||||
let text = "Ele disse que está na Unigranrio-RJ.";
|
||||
assert_eq!(crate::check_spelling_in(text, crate::ProofLang::Pt).len(), 1, "Unigranrio isn't in the dictionary");
|
||||
// Added as the context menu adds it, hyphen and all (#2082).
|
||||
crate::add_word("Unigranrio-RJ");
|
||||
assert!(crate::check_spelling_in(text, crate::ProofLang::Pt).is_empty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user