Skip to content

Fix duplicate key.focused condition and refactor to 'when' for clarity#558

Open
ColtonLeighton wants to merge 2 commits intoscribe-org:mainfrom
ColtonLeighton:fix-duplicate-key-condition
Open

Fix duplicate key.focused condition and refactor to 'when' for clarity#558
ColtonLeighton wants to merge 2 commits intoscribe-org:mainfrom
ColtonLeighton:fix-duplicate-key-condition

Conversation

@ColtonLeighton
Copy link

Contributor checklist


Description

This pull request fixes a duplicate key.focused check in the text color logic. The original code looked like this:

if (key.focused) {
Color.WHITE
} else if (key.focused) {
mPrimaryColor.getContrastColor()
}

The second key.focused branch could never be reached, because the first if already handles that case. It seems the intention was to check key.pressed instead.

The logic has also been cleaned up using a when statement for readability:

paint.color = when {
key.focused -> Color.WHITE
key.pressed -> mPrimaryColor.getContrastColor()
else -> mTextColor
}

No functional behavior was changed beyond fixing the unreachable condition, but this makes the code clearer and easier to maintain.

@github-actions
Copy link

Thank you for the pull request! 💙

The Scribe-Android team will do our best to address your contribution as soon as we can. If you're not already a member of our public Matrix community, please consider joining! We'd suggest that you use the Element client as well as Element X for a mobile app, and definitely join the General and Android rooms once you're in. Also consider attending our bi-weekly Saturday dev syncs. It'd be great to meet you 😊

Note

Scribe uses Conventional Comments in reviews to make sure that communication is as clear as possible.

@github-actions
Copy link

github-actions bot commented Mar 10, 2026

Maintainer Checklist

The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

  • Tests for changes have been written and the unit test, linting and formatting workflows within the PR checks do not indicate new errors in the files changed

    • Tests may need to be reran as they're at times not deterministic
  • The CHANGELOG has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

First PR Commit Check

  • The commit messages for the remote branch should be checked to make sure the contributor's email is set up correctly so that they receive credit for their contribution
    - The contributor's name and icon in remote commits should be the same as what appears in the PR
    - If there's a mismatch, the contributor needs to make sure that the email they use for GitHub matches what they have for git config user.email in their local Scribe-Android repo (can be set with git config --global user.email "GITHUB_EMAIL")

@andrewtavis
Copy link
Member

Thanks so much for the PR, @ColtonLeighton! Great to have you finding these issues :) Looks like we a inting issue. Could you send along a fix for it? From there we should be able to bring this in quickly 😊

} else {
mTextColor
}
// Set key text color based on state: focused keys are white, pressed keys use a contrasting color, otherwise default text color
Copy link
Member

Choose a reason for hiding this comment

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

And can you change this so the comment isn't referring only to light mode, but rather is independent of color mode?

Copy link
Member

Choose a reason for hiding this comment

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

And ideally end a comment that is its own line with a period so it's a complete sentence :)

mTextColor
}
// Set key text color based on state: focused keys are white, pressed keys use a contrasting color, otherwise default text color
// Using 'when' makes the logic clearer and avoids evaluating duplicate conditions
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this comment, but agree that this is nicer :)

@andrewtavis
Copy link
Member

Post linting fix and the above changes, I think we'll be good to go 😊

@andrewtavis
Copy link
Member

And also check out the testing section of the contributing guide to test your next commit before you send it :)

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