Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: when spellcheck only has one suggestion mention it directly as in matcher

hippietraile115211feef3
diff --git a/harper-core/src/linting/spell_check.rs b/harper-core/src/linting/spell_check.rs
index 1a9e2e082..51bbbe368 100644
--- a/harper-core/src/linting/spell_check.rs
+++ b/harper-core/src/linting/spell_check.rs
@@ -76,17 +76,27 @@ impl<T: Dictionary> Linter for SpellCheck<T> {
}
let suggestions = possibilities
- .into_iter()
+ .iter()
.map(|word| Suggestion::ReplaceWith(word.to_vec()));
+ // If there's only one suggestion, save the user a step in the GUI
+ let message = if suggestions.len() == 1 {
+ format!(
+ "Did you mean “{}”?",
+ possibilities.last().unwrap().iter().collect::<String>()
+ )
+ } else {
+ format!(
+ "Did you mean to spell “{}” this way?",
+ document.get_span_content_str(word.span)
+ )
+ };
+
lints.push(Lint {
span: word.span,
lint_kind: LintKind::Spelling,
suggestions: suggestions.collect(),
- message: format!(
- "Did you mean to spell “{}” this way?",
- document.get_span_content_str(word.span)
- ),
+ message,
priority: 63,
})
}