Skip to content

fix: correctly detect shift key only for uppercase letters #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

benny123tw
Copy link
Contributor

Description

When I press the return key (\r) on macOS, the key object incorrectly indicates that the shift key is also pressed:

{
  input: '\r',
  key: {
    upArrow: false,
    downArrow: false,
    leftArrow: false,
    rightArrow: false,
    pageDown: false,
    pageUp: false,
    return: true,
    escape: false,
    ctrl: false,
    shift: true,
    tab: false,
    backspace: false,
    delete: false,
    meta: false
  }
}

Root Cause

The previous logic inferred the shift key was pressed for any single character where input[0].toUpperCase() === input[0]. This included not only uppercase letters, but also control characters (like \r) and symbols, leading to incorrect detection of the shift key.

Solution

This PR updates the shift key detection logic to use a regular expression (/^[A-Z]$/) that matches only uppercase ASCII letters. Now, key.shift will only be set to true when the input is an uppercase letter, and not for control characters or symbols.

Testing

  • Verified that pressing the return key no longer sets key.shift to true.
  • Confirmed that uppercase letter input (e.g., Q) still sets key.shift to true.

@sindresorhus sindresorhus merged commit f6faae1 into vadimdemedes:master Apr 29, 2025
2 checks passed
JunYang-tes pushed a commit to JunYang-tes/preactink that referenced this pull request May 12, 2025
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