Skip to content

feat(keyboard): show closest word suggestion on invalid command #640#642

Open
prince-0408 wants to merge 1 commit intoscribe-org:mainfrom
prince-0408:feat/suggest-closest-match-on-invalid-command
Open

feat(keyboard): show closest word suggestion on invalid command #640#642
prince-0408 wants to merge 1 commit intoscribe-org:mainfrom
prince-0408:feat/suggest-closest-match-on-invalid-command

Conversation

@prince-0408
Copy link
Copy Markdown
Contributor

Summary

When a translate, conjugate, or plural command returns no result, instead of showing a generic "Not in Wikidata/Wiktionary" error, the command bar now shows "Did you mean: X?" using the closest match from the autocomplete lexicon.

Closes #640

Problem & Solution

Scenario Before After
User types "hause" (typo) "Not in Wikidata" "Did you mean: Haus?"
User types "zzzzz" (nonsense) "Not in Wikidata" "Not in Wikidata" (fallback)
Word exists but not in translation DB "Not in Wiktionary" "Did you mean: X?" if close match found

Changes

File Description
CommandVariables.swift Added didYouMeanSuggestion(for:) — progressively shortens input to find closest prefix match (min 2 chars)
KeyboardViewController.swift All 4 invalid blocks updated to show suggestion before falling back to generic error

Notes

  • Falls back to existing invalidCommandMsg when no match found — zero regression

…e-org#640

Add didYouMeanSuggestion(for:) helper in CommandVariables that
progressively shortens the input word to find the closest prefix
match in autocomplete_lexicon (minimum 2 chars).

Update all 4 invalid command blocks in KeyboardViewController:
- Return key: translate (uses wordToTranslate global)
- Return key: conjugate (uses verbToConjugate global)
- Translate key with selected text
- Conjugate key with selected text
- Plural key with selected text

Each block shows 'Did you mean: X?' when a close match is found,
falls back to existing invalidCommandMsg when no match exists.
Existing alreadyPlural behavior is untouched.

Closes scribe-org#640
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Thank you for the pull request! 💙🩵

The Scribe-iOS team will do our best to address your contribution as soon as we can. The following are some important points:

  • Those interested in developing their skills and expanding their role in the community should read the mentorship and growth section of the contribution guide
  • If you're not already a member of our public Matrix community, please consider joining!
    • We'd suggest that you use the Element client as well as Element X for a mobile app
    • Join the General and iOS rooms once you're in
  • Also consider attending our bi-weekly Saturday developer syncs!
    • Details are shared in the General room on Matrix each Wednesday before the sync
    • It would be great to meet you 😊

Note

Scribe uses Conventional Comments in reviews to make sure that communication is as clear as possible.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Maintainer Checklist

The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

  • Tests for changes have been written and the CI unit test, linting and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The CHANGELOG has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show closest word suggestion when translation or conjugation is invalid

1 participant