Skip to content

refactor: extract KeyboardStateManager from GeneralKeyboardIME (#426) - #678

Merged
andrewtavis merged 2 commits into
scribe-org:mainfrom
prince-0408:refactor/keyboard-state-manager-426
Aug 20, 2026
Merged

refactor: extract KeyboardStateManager from GeneralKeyboardIME (#426)#678
andrewtavis merged 2 commits into
scribe-org:mainfrom
prince-0408:refactor/keyboard-state-manager-426

Conversation

@prince-0408

Copy link
Copy Markdown
Collaborator

Description

This PR is Part 7 in modularizing GeneralKeyboardIME for #426.

It extracts ScribeState tracking, state transitions, invalid command state recording, and state query helpers out of GeneralKeyboardIME.kt into a standalone, unit-testable helper class KeyboardStateManager.

Detailed Changes Table:

File / Component Changes Applied Detailed Impact
KeyboardStateManager.kt Created standalone helper encapsulating currentState (ScribeState), invalidCommandSource (ScribeState), transition methods (moveToState, moveToIdle, setInvalidState, reset), and state query getters (isIdle, isSelectCommand, isCommandBarActive, isInvalid, isAlreadyPlural). Extracts state management responsibility out of GeneralKeyboardIME.kt into a dedicated, unit-testable class.
GeneralKeyboardIME.kt Instantiated stateManager and delegated currentState & invalidCommandSource properties. Refactored state transition methods (moveToIdleState(), onScribeKeyOptionsClicked(), onTranslateClicked(), onConjugateClicked(), onPluralClicked(), handlePluralOrTranslateState(), handleConjugateState()) to delegate to KeyboardStateManager. Reduces complexity and responsibility of GeneralKeyboardIME.kt while preserving 100% backward compatibility for external callers.
KeyboardStateManagerTest.kt Added unit tests covering initial state defaults, state transitions (moveToState, moveToIdle), invalid state source recording (setInvalidState), query getters (isIdle, isCommandBarActive, etc.), and state reset (reset). Ensures 100% unit test coverage for state management logic.

Key Benefits:

  • Modular & Decoupled Architecture: Moves state management logic out of GeneralKeyboardIME.kt into a single-responsibility helper class.
  • Improved Testability: State transitions can now be unit-tested independently of Android service lifecycles.
  • Zero Behavioral / API Breakage: Preserves exact state transitions and retains property delegation for zero breaking changes across existing helpers (KeyHandler, BackspaceHandler, SuggestionHandler, ClipboardHandler, KeyboardUIManager, etc.).

Related Issue

Refactors part of #426

@andrewtavis

Copy link
Copy Markdown
Member

Thanks for the PR, @prince-0408! Maintainers are a bit busy for the next few days. @linreal, would you have a moment to take a look again? 😊

@linreal linreal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@andrewtavis andrewtavis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: All's looking good on my end as well in terms of code and functionality. Thanks, @prince-0408! And thanks for the initial review, @linreal!

@andrewtavis
andrewtavis merged commit 173716b into scribe-org:main Aug 20, 2026
6 checks passed
@prince-0408

prince-0408 commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

praise: All's looking good on my end as well in terms of code and functionality. Thanks, @prince-0408! And thanks for the initial review, @linreal!

Hi @andrewtavis There are a few more refactoring PRs that I think would be good to raise. If you’re okay with it, I can work on those as well and create the PRs.

@andrewtavis

Copy link
Copy Markdown
Member

Sounds good, @prince-0408! Feel free to write into #426 with your ideas, if they're not already covered by what's been planned there already.

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.

4 participants