Skip to content

android: fix earlier words (labs) (#3019) - #3029

Open
opencodejr[bot] wants to merge 1 commit into
devfrom
agent/issue-3019
Open

opencodejr[bot] wants to merge 1 commit into
devfrom
agent/issue-3019

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Adds Labs › Keyboard › Fix earlier words, off by default (#3019). Requested and specified by @dgunay. This is written fresh from the issue's description; no code was taken from their fork.

With the toggle on, the strip offers up to three words (its three slots) after its usual 100 ms pause when the cursor is back in a finished word: after deleting back into it, after tapping it, or right at its start.

  • What was typed, first, if autocorrect changed it. While the toggle is on, the field keeps its last 20 one-word fixes in memory and drops them when another field opens.
  • Other words its letters could be. New SpatialDecoder.alternatives reads the letters as taps on the key centres. It uses the last grid typed on, or an even grid built from the layout's rows. One letter may be missed, extra or swapped. A reading is kept only when it fits the word pairs on both sides at least EARLIER_MARGIN = 3 nats better than the word already there.

Tapping one replaces the whole word in one batch edit. This adds KeyboardTextTarget.deleteAfter, which defaults to false so existing test fakes still compile. Choosing the original calls feedback.undo, the same count Delete's undo uses, and drops that fix.

Nothing is offered:

  • right after a closing quote or apostrophe, where the cursor is past the word
  • for words joined to a digit, @ # / _ - : or a dot (handles, paths, numbers, addresses, links)
  • for words with inner capitals, or the user's own dictionary words
  • in passwords, URL fields, TYPE_NULL editors, symbol pages and pads
  • while a word is being typed or swiped, or while Undo dictation is offered

With the toggle off, nothing is recorded or scheduled and the keyboard is unchanged.

Files:

  • new keyboard/EarlierWords.kt: fix list, finding the word around the cursor, building the offer
  • KeyboardEngine: wiring
  • TypingPreferences.fixEarlierWords
  • HexSettings: the toggle
  • strings: en, zh-rCN
  • android/README.md: Labs › Keyboard paragraph

Changes after review:

  • spot() returns null with the cursor right after a closing quote ('teh', dogs', curly ’), so a pick can no longer delete the quote.
  • The word before must contain a letter, so a lone apostrophe no longer counts as one.
  • Recording fixes and remembering the key grid are gated on the toggle.
  • The total is capped at Suggestion.SLOTS and the README wording matches.
  • The Spot doc comment is corrected.
  • The margin was raised from 0.5 to 3 nats after a test showed "a cat sat" offering "car". The constant has a comment with the measured values.

Known limits:

  • "by" → "buy" in "to by a car" (the issue's own example) is not offered: the word pairs score both about the same.
  • Pairs two edits apart (there/their, no/know) are out of reach.
  • The issue's 81.8% → 88.4% figures are not re-measured for this version.

Testing:

  • EarlierWordsTest (3 tests, real en.hextm, JUnit with a standalone Kotlin 2.0 compiler) passes. It covers:
    • finding the word and its neighbours, and closing quotes and possessives in straight and curly forms
    • skipping handles, paths and addresses
    • offers: "going too the" → "to", "came form the" → "from", "I red the" → "read"
    • no offer for words that fit, including "a cat sat", "the cat is", "my cat is", "a cat and" and "in form of"
    • the original-first offer, forgetting an undone fix, and the 20-fix cap
  • The changed Kotlin files except HexSettings.kt compile against android.jar with no new errors.
  • No full Gradle build was available, so HexSettings.kt was not compiled, and the feature was not tried on a device.
  • python3 scripts/code-shape.py --check passes.
  • Nothing under ios/ was touched.

Closes #3019

This branch has not been deployed

No deployments
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.

Android keyboard: fix earlier words (strip offers alternatives for a finished word)

0 participants