Skip to content

fix(expander): match typed text and correct autocorrection prefix lengths - #570

Closed
AsafMah wants to merge 4 commits into
LeanBitLab:mainfrom
AsafMah:asafmah-upstream-exact-expansion
Closed

AsafMah wants to merge 4 commits into
LeanBitLab:mainfrom
AsafMah:asafmah-upstream-exact-expansion

Conversation

@AsafMah

@AsafMah AsafMah commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Make regex text expansion depend on actual typed text, calculate prefix removal from the composing word, respect deliberate manual suggestion choices, and avoid reporting autocorrections that expansion replaced.

This addresses a reproduced regex configuration related to the report that typing cps expands a cpp shortcut. A literal cpp entry already rejects typed cps; the reporter's original UI/configuration was unavailable, so this does not claim to reproduce every configuration.

Reproduction and behavior

  • False trigger: configure regex __regex__:cpp, type cps, provide pending correction cpp, then type a space. Previously the matcher synthesized cpscpp and expanded it. Now normal correction produces cpp without triggering the macro.
  • Prefix accounting: configure regex \.py with an empty configured prefix and separator triggering. Start with keep ., compose py, provide correction python, then type a space. After fixing matching alone, this left keep .EXPANDED . Prefix accounting now uses the raw composing word and produces keep EXPANDED . Shorter corrections are covered too.
  • Explicit selection: with that same prefixed regex, manually choosing python, p, or by must produce the chosen word, not expansion based on the abandoned py. These cases passed on original upstream but regressed when synthetic matching was removed. Expansion is now bypassed for a different manual choice. Selecting the actual shortcut, including a case-only variation, still expands and can be undone. Regex matching does not fabricate trigger text from a picked candidate either.
  • Editor notification: expansion with pending python previously sent CorrectionInfo{#7 "py" -> "python"} even though the editor contained keep EXPANDED . Expansion now reports its outcome to the automatic-commit caller so this uncommitted correction is not announced. Real autocorrection notifications remain intact.

Implementation

Four isolated commits, each with editor-path regression coverage:

  1. c9dc2d7a3970335b8ad000755060e2a838949307: match regex shortcuts against actual typed text.
  2. c431af241917adb830ad404e905d56ea751c4d2e: measure matched prefixes using the composing word before automatic correction.
  3. e8a636b32c5459d7b48d8c125b7d7d907579f0d3: preserve explicit manual choices that differ from the composing word, while retaining same-word/case-only expansion and undo.
  4. 659c33dd76f67030ac0e74c37ebacfce96578423: return the private expansion outcome and suppress stale automatic-correction metadata/candidate statistics only when expansion replaced the candidate.

Only TextExpanderUtils.kt, InputLogic.kt, and InputLogicTest.kt change. No branding, dependencies, translations, test skips, or baseline changes.

Validation

Run on upstream base b718d832c41ba01e1cce613f14e6209c279e9d17, using JDK 21.0.12 and the existing Android SDK/build configuration:

:app:testStandardDebugUnitTest --tests '*InputLogicTest'

Fresh JUnit XML: 104 tests, 103 passed, 1 existing ignored Hangul test, 0 failures, 0 errors. The ignored case is insertLetterIntoWordHangulFails. All 14 added tests were explicitly checked as present and passing.

Failing-before-fix evidence was observed for synthetic regex matching, unequal-length prefix removal, manual-choice overriding, and incorrect editor correction metadata. Manual-choice fixtures were also run with the production files verified identical to the original upstream base: the python/p/by and full-regex cases passed there, establishing the introduced regression. A separately named suffix-only y choice exposed a pre-existing related defect that the same manual-choice gate also prevents.

Coverage includes actual cpp expansion and undo in immediate/separator modes, literal/regex behavior, surrounding text and cursor preservation, longer/shorter/same-length manual choices, case-insensitive same-word selection, and real correction notification offset/old/new text with expansion disabled or unmatched. The original two source commits remain unchanged, confirmed by range-diff.

Limits

Validation exercises the existing Robolectric InputLogic/editor integration and captures actual InputConnection.commitCorrection calls. No physical-device UI or APK validation was performed for this standalone upstream contribution.

AsafMah and others added 2 commits September 29, 2026 17:56
Do not append pending autocorrections to the expansion search buffer. Cover cps corrected to cpp, real cpp triggers, immediate and separator expansion, and undo using the editor input path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Compute matched prefix length from the composing typed word, not a longer or shorter correction. Retain selected-candidate behavior for manual picks and verify prefix, surrounding text, cursor, and selection paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AsafMah
AsafMah marked this pull request as draft September 29, 2026 14:59
AsafMah and others added 2 commits September 29, 2026 18:10
Skip expansion when a manually picked word differs from the actual composing word. Preserve same-word and case-only shortcut expansion and undo. Cover prefixed and full regex matches, longer and shorter choices, and suffix-only candidates through the editor path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Return the expansion outcome from commitChosenWord and skip correction metadata and candidate statistics when expansion replaced the candidate. Record editor commitCorrection callbacks in tests; preserve real autocorrection notifications with expansion disabled or unmatched.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AsafMah
AsafMah marked this pull request as ready for review September 29, 2026 15:19
@AsafMah AsafMah closed this Sep 29, 2026
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