refactor(inputlogic): consolidate backspace state into BackspaceUnitStack (#31)#77
Merged
Conversation
…tack (#31) The fragment- and whole-word-backspace length bookkeeping lived in three fields scattered across InputLogic (mGestureFragmentBoundaries + mLastGestureCommittedLength + mLastGestureCommittedFragmentLengths), read and mutated by several interleaved branches — the most corruption-prone area (PR #11 class). Extract them into one BackspaceUnitStack: the active composing word's fragment boundaries and the last committed gesture word's total + per-fragment lengths, with all the boundary/pop math as named methods. InputLogic keeps the policy (when to record/pop) and editor side effects; the stack owns only the length bookkeeping. Pure, behaviour-preserving extraction — same decisions, same outputs. Adds BackspaceUnitStackTest: 17 direct unit tests for the pop/commit math that previously had only indirect coverage via InputLogic. Verification: :app:testOfflineDebugUnitTest --tests InputLogicTest --tests BackspaceUnitStackTest -> 120 completed, 3 failed (pre-existing baseline: autospace-indicator / Hangul / autocorrect-revert), 1 skipped. 0 new failures; full #21 backspace corpus green; all 17 stack tests green. Increment 1 of #31 (state consolidation). The committed-gesture pop paths (gesture-only, not JVM-reachable) are migrated structurally but need on-device confirmation; the single-plan path collapse is the follow-up.
…nitStack A gesture word committed with no recorded fragments must still set committedLength (arms the first-backspace whole-word delete) while keeping the fragment list empty — the empty-list commit case flagged in review as the easiest place to silently drop the length.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #31 (increment 1 — state consolidation).
Problem
The fragment- and whole-word-backspace bookkeeping lived in three fields scattered across
InputLogic—mGestureFragmentBoundaries(composing-word fragments),mLastGestureCommittedLength+mLastGestureCommittedFragmentLengths(last committed gesture word) — read and mutated by several interleavedhandleBackspaceEventbranches plus the commit writer. This is the most corruption-prone area in the codebase (the PR-#11 word-mash class).Change
Extract them into one
BackspaceUnitStack: the active composing word's fragment boundaries + the last committed gesture word's total/per-fragment lengths, with all the boundary, pop, and commit-delta math as named methods.InputLogickeeps the policy (when to record/pop) and the editor side effects (setComposingText,deleteTextBeforeCursor, stats); the stack owns only the length bookkeeping.Pure, behavior-preserving extraction — same gating, same decisions, same outputs.
InputLogic.javashrinks by ~54 lines.Why this first
BackspaceUnitStackis a plain data structure, so the corruption-prone pop/commit math is now directly unit-testable — previously it had only indirect coverage throughInputLogic. NewBackspaceUnitStackTestadds 17 focused tests (single/multi-fragment pop, stale-boundary trim, the defensive fallback, commit-delta lengths, defensive copies, composing/committed independence).Verification
:app:testOfflineDebugUnitTest --tests "*InputLogicTest" --tests "*BackspaceUnitStackTest"→ 120 completed, 3 failed, 1 skipped....AutospaceIndicator,insertLetterIntoWordHangulFails,revert autocorrect on delete) — 0 new.Scope / follow-up (needs your on-device pass)
handleBackspaceEvent) are gesture-only — not JVM-reachable — so they're migrated structurally (identical math, relocated) but want on-device confirmation before merge.plan → applypop) is the next increment, on top of this consolidated state. Builds on the green corpus + these unit tests as the net.Stacked on #72 (corpus) which is already merged to
dev.