Skip to content

fix: filter invalid key behavior tokens during keyboard parsing - #2067

Open
ENOA-REIAH-UION wants to merge 2 commits into
osfans:developfrom
ENOA-REIAH-UION:key-action
Open

fix: filter invalid key behavior tokens during keyboard parsing#2067
ENOA-REIAH-UION wants to merge 2 commits into
osfans:developfrom
ENOA-REIAH-UION:key-action

Conversation

@ENOA-REIAH-UION

Copy link
Copy Markdown
Contributor

Pull request

Issue tracker

Fixes will automatically close the related issues

Fixes #
Fixes #

Feature

Describe features of this pull request

Code of conduct

Code style

Build pass

  • make debug

Manually test

  • Done

Code Review

  1. No wildcards import
  2. Manual build and test pass
  3. GitHub Action CI pass
  4. At least one contributor review and approve
  5. Merged clean without conflicts
  6. PR will be merged by rebase upstream base

Daily build

Login and download artifact at https://github.com/osfans/trime/actions

Additional Info

Since commit 5b78b88, getLabel() dynamically resolves space key label.

Caching KeyAction instances for space keys is now safe and no longer risks stale labl.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to harden keyboard theme parsing by filtering out invalid key-behavior tokens, and simplifies KeyActionManager caching logic.

Changes:

  • Refactors TextKeyboard.TextKey.decode() to build the behaviors map via associateWith(...) and filter out invalid tokens.
  • Simplifies KeyActionManager.getAction(KeyActionToken) to use MutableMap.getOrPut(...) for caching.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/main/java/com/osfans/trime/data/theme/model/TextKeyboard.kt Refactors behavior-token decoding + adds filtering for “invalid” tokens during keyboard parsing.
app/src/main/java/com/osfans/trime/data/theme/KeyActionManager.kt Simplifies action caching logic using getOrPut.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +117 to +124
.filter { (behavior, token) ->
token?.let {
when (it) {
is KeyActionToken.Plain -> it.token.isNotEmpty()
is KeyActionToken.Inline -> listOfNotNull(it.token.commit, it.token.text, it.token.label).isNotEmpty()
}
} ?: (behavior == KeyBehavior.CLICK)
},
actionCache[token] = it
}
}
fun getAction(token: KeyActionToken): KeyAction = actionCache.getOrPut(token) { KeyAction(token) }
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.

2 participants