Skip to content

English autocorrect, auto-complete with a cycle, and a Ctrl double-tap toggle - #6

Open
orisup1 wants to merge 9 commits into
mainfrom
features
Open

English autocorrect, auto-complete with a cycle, and a Ctrl double-tap toggle#6
orisup1 wants to merge 9 commits into
mainfrom
features

Conversation

@orisup1

@orisup1 orisup1 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Everything on features since cd29691. Three user-visible features plus the plumbing they needed.

English autocorrect (src/spell.rs)

A noisy-channel corrector — argmax_c P(c)·P(t|c), Kernighan/Church/Gale — with the two factors added in log space rather than ordered lexicographically, so a candidate can win either by being the likelier slip or by being the far likelier word. The channel model is Brill & Moore string-to-string edits, so apparantapparent is one decision rather than three unrelated letter edits, which is what brings maintainance, restaraunt and fisicalphysical into range. Candidates come from scanning the frequency list, not from generating an edit ring.

Runs only under an English layout, only on words the dictionary doesn't know, never on ALL CAPS or anything with a digit.

Auto-complete (src/complete.rs)

Tap Right Shift mid-word to finish it. Tap again to cycle through the next candidates, and once more to get back exactly what you typed, capitalization included — that wrap-around is the safety property, since it makes a wrong guess cost a keypress instead of a deletion.

Candidates are ranked by what the tap actually saves you (letters filled in, weighted by P ∝ 1/rank), not by raw frequency: a completion that adds one letter to a five-letter prefix isn't worth the key that asked for it. Frequency still dominates a lopsided pair.

Abbreviations from <config>/recast/abbrev.txt expand when a word is finished, and are offered by the first tap too.

Ctrl double-tap (LastAction in each platform listener)

One gesture, two directions, decided by what happened to the word rather than by the tap:

  • after a correction — put back what you typed, restore the layout if the fix changed it, and retire the word so the next repetition isn't corrected again
  • after a word that was left alone because you had retired it — take it off the list, ignore.txt on disk included, and correct it after all

Only the word the cursor is still sitting on: the payload is dropped by the next keystroke and by a mouse click, because both directions erase backwards from the cursor. A correctly spelled word arms nothing.

The ignore.txt rewrite drops only lines that are the word, copies comments and everything else through byte for byte, and replaces the file by rename.

macOS fix worth calling out

EVENT_MASK was missing kCGEventFlagsChanged, and macOS delivers Shift, Ctrl and Caps Lock only as that event type. So the Right Shift completion trigger had never fired on macOS, and the shift behind every capital was invisible to the word buffer. Added the mask bit and handle_flags_changed, which recovers press-vs-release from CGEventGetFlags using the device-dependent bits (kCGEventFlagMask* can't tell left from right).

Testing

83 tests. The unit tests pin the rules; spell::real_data and complete::real_data pin what those rules do to the lists actually shipped, so a threshold change that looks harmless in isolation shows up.

Linux is built, tested and lint-clean. Windows and macOS are type-checked and clippy-clean via cross-target cargo checknot run on real hardware. The macOS flagsChanged path in particular is new code that wants a smoke test before it's trusted.

exec/recastLinux and exec/ReCast.exe are refreshed from this tree; the macOS artifacts are stale and the README now says so.

Known rough edges

The gesture state machine is duplicated across the three platform listeners and has no test coverage — extracting it behind one key-type-generic module is the obvious next change.

🤖 Generated with Claude Code

orisup1 added 8 commits July 23, 2026 01:30
added compiled windows version to the exec/ folder
Switch homographs to the other layout only when its reading is a
top-2000 word and the current reading is unlisted or >=10x rarer.
Adds embedded en/he frequency lists and RECAST_FREQ toggle (default on)
taskbar icon and ASCII banner on startup
when a word is typed and corrected, the user will double press to revert
it and add to ignore list, if the user wants the word back simply double
press again to correct and remove from ignore list

chore: refresh Linux/Windows binaries, document exec/

Rebuild `exec/recastLinux` and `exec/ReCast.exe` from the current tree so
the committed artifacts include the completion cycle and the Ctrl
double-tap gesture.

The Windows build is cross-compiled (x86_64-pc-windows-gnu); it imports
only system DLLs plus the UCRT, and `build.rs` embeds the icon and
version resources through the mingw-prefixed windres, so it is equivalent
to a native build. The macOS artifacts are left alone — they can't be
linked here — and the README now says which of the four are current.

README also gains a note that RECAST_DEBUG logs every typed word.
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.

1 participant