Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: if spellcheck only has one suggestion mention it directly #626

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
feat: when spellcheck only has one suggestion mention it directly as …
…in matcher

When the spellchecker has suggestions you have to click on Quick Fix to see them.

But when `matcher.rs` suggests a fix it tells you directly, without having to click on Quick Fix

So use the same text in spell_check as in matcher when there's only one suggestion.
hippietrail committed Feb 9, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e115211feef3be510f220369be77799a0391d4d7
20 changes: 15 additions & 5 deletions harper-core/src/linting/spell_check.rs
Original file line number Diff line number Diff line change
@@ -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,
})
}