Skip to content

refactor(inputlogic): consolidate backspace state into BackspaceUnitStack (#31)#77

Merged
AsafMah merged 2 commits into
devfrom
feat/a7-backspace-stack
Jun 10, 2026
Merged

refactor(inputlogic): consolidate backspace state into BackspaceUnitStack (#31)#77
AsafMah merged 2 commits into
devfrom
feat/a7-backspace-stack

Conversation

@AsafMah

@AsafMah AsafMah commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Part of #31 (increment 1 — state consolidation).

Problem

The fragment- and whole-word-backspace bookkeeping lived in three fields scattered across InputLogicmGestureFragmentBoundaries (composing-word fragments), mLastGestureCommittedLength + mLastGestureCommittedFragmentLengths (last committed gesture word) — read and mutated by several interleaved handleBackspaceEvent branches 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. InputLogic keeps 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.java shrinks by ~54 lines.

Why this first

BackspaceUnitStack is a plain data structure, so the corruption-prone pop/commit math is now directly unit-testable — previously it had only indirect coverage through InputLogic. New BackspaceUnitStackTest adds 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.

  • 3 failures = the AGENTS.md-documented pre-existing baseline (...AutospaceIndicator, insertLetterIntoWordHangulFails, revert autocorrect on delete) — 0 new.
  • The full A3b: JUnit replay harness + golden corpus #21 backspace corpus stays green; all 17 stack tests green.

Scope / follow-up (needs your on-device pass)

  • The composing-side paths are fully corpus-covered (taps/fragments).
  • The committed-gesture pop paths (paths 5/6 in handleBackspaceEvent) are gesture-only — not JVM-reachable — so they're migrated structurally (identical math, relocated) but want on-device confirmation before merge.
  • The deeper A7: Unify backspace into one revertible input-unit stack #31 goal (collapse the 6 backspace branches into a single plan → apply pop) 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.

AsafMah added 2 commits June 10, 2026 09:29
…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.
@AsafMah AsafMah merged commit 57d1e15 into dev Jun 10, 2026
1 check passed
@AsafMah AsafMah deleted the feat/a7-backspace-stack branch June 10, 2026 07:05
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