Skip to content

Conversation

@Aotumuri
Copy link
Member

Description:

Guard global keydown/keyup handlers to ignore events from text/textarea/contenteditable targets (except Escape/active keys) so
gameplay shortcuts don’t trigger while typing in the quick chat player search.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

aotumuri

@Aotumuri Aotumuri requested a review from a team as a code owner November 27, 2025 03:33
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

Walkthrough

Modified keyboard event handlers to add early-return guards that prevent global keybinds from triggering when focus is within text input elements (input fields, textareas, or contenteditable regions). The Escape key remains actionable in all contexts.

Changes

Cohort / File(s) Summary
Input Focus Guards
src/client/InputHandler.ts
Added early return checks in keydown and keyup handlers to skip processing when focus is on text input elements, preserving Escape key functionality

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify guard logic correctly identifies input/textarea/contenteditable elements
  • Confirm Escape key bypass works as intended in all scenarios
  • Check that guard applies consistently to both keydown and keyup event paths

Suggested reviewers

  • Duwibi
  • scottanderson
  • evanpelle

Poem

🎹 Keys once wild while typing fast,
Now politely wait—at last!
Escape still breaks through the din,
Text input flows, no accidents win. ✨

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preventing keyboard shortcuts from firing while typing in quick chat search, which directly matches the changeset's purpose of adding guards to keyboard event handlers.
Description check ✅ Passed The description is directly related to the changeset, explaining the guards added to global keydown/keyup handlers and their purpose in preventing shortcuts during text input.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/client/InputHandler.ts (1)

293-300: Consider extracting the text input check to reduce duplication.

The same text input detection logic appears in both keydown and keyup handlers. Extract it to a helper method for cleaner code.

Add this helper method after line 625:

  private isTextInput(target: EventTarget | null): boolean {
    const element = target as HTMLElement | null;
    return (
      element?.tagName === "INPUT" ||
      element?.tagName === "TEXTAREA" ||
      element?.isContentEditable === true
    );
  }

Then simplify both guards:

     window.addEventListener("keydown", (e) => {
-      const target = e.target as HTMLElement | null;
-      const isTextInput =
-        target?.tagName === "INPUT" ||
-        target?.tagName === "TEXTAREA" ||
-        target?.isContentEditable;
-      if (isTextInput && e.code !== "Escape") {
+      if (this.isTextInput(e.target) && e.code !== "Escape") {
         return;
       }
     window.addEventListener("keyup", (e) => {
-      const target = e.target as HTMLElement | null;
-      const isTextInput =
-        target?.tagName === "INPUT" ||
-        target?.tagName === "TEXTAREA" ||
-        target?.isContentEditable;
-      if (isTextInput && !this.activeKeys.has(e.code)) {
+      if (this.isTextInput(e.target) && !this.activeKeys.has(e.code)) {
         return;
       }

Also applies to: 343-350

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c38c25a and ae76f25.

📒 Files selected for processing (1)
  • src/client/InputHandler.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/client/InputHandler.ts (4)
src/core/execution/NukeExecution.ts (1)
  • target (43-45)
src/core/game/GameImpl.ts (1)
  • target (592-598)
src/core/game/PlayerImpl.ts (1)
  • target (531-534)
src/core/game/AttackImpl.ts (1)
  • target (26-28)
🔇 Additional comments (2)
src/client/InputHandler.ts (2)

293-300: LGTM! Keydown guard works correctly.

The guard properly blocks shortcuts when typing in text inputs while preserving Escape functionality. This ensures players can close dialogs even when a text field has focus.


343-350: LGTM! Keyup guard maintains proper key state.

The activeKeys check correctly handles the edge case where a key is pressed outside a text input and released inside it, ensuring the key state is properly cleaned up.

@Aotumuri Aotumuri requested a review from evanpelle December 6, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants