Skip to content

fix: right-click cancels warship/boat selection instead of opening the menu - #4729

Merged
evanpelle merged 2 commits into
openfrontio:mainfrom
eastwoodgrant:fix/4692-cancel-warship-selection
Jul 27, 2026
Merged

evanpelle merged 2 commits into
openfrontio:mainfrom
eastwoodgrant:fix/4692-cancel-warship-selection

Conversation

@eastwoodgrant

Copy link
Copy Markdown
Contributor

Resolves #4692

Problem

With a warship/boat selected, right-clicking opened the radial context menu instead of cancelling the selection. InputHandler.onContextMenu emitted ContextMenuEvent unconditionally — there was no branch for an active unit selection, and the EventBus has no way for another listener to suppress the menu.

Fix

onContextMenu already cancels an in-progress action on right-click — if a ghost structure is being placed, it clears it and returns instead of opening the menu. This applies the same pattern to unit selection:

  • InputHandler already listens to UnitSelectionEvent (to set the cursor); it now also tracks unitSelectionActive (single or multi selection).
  • In onContextMenu, if a unit is selected, emit a deselect and return before emitting ContextMenuEvent.

Fully contained in InputHandler.ts — no new shared state, no changes to the selection controller or renderer.

Testing

  • Added regression tests in tests/InputHandler.test.ts: right-click with a warship selected cancels the selection and does not open the menu; with nothing selected the menu still opens.
  • Full suite passes (npm test).
  • Verified live in a running game: real right-click on the input overlay with a warship selected fired only a deselect (no context-menu event, radial menu not shown); with nothing selected the radial menu opened normally.

Discord: granster9

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cba24896-0ca1-4ae7-a9b9-e31c9621f2cc

📥 Commits

Reviewing files that changed from the base of the PR and between b65c432 and b155f68.

📒 Files selected for processing (1)
  • tests/InputHandler.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/InputHandler.test.ts

Walkthrough

InputHandler tracks active unit selections and cancels them on right-click before opening a context menu. Tests verify behavior with and without a selected warship.

Changes

Unit deselection behavior

Layer / File(s) Summary
Track active unit selection
src/client/InputHandler.ts
Adds and updates a flag indicating whether a unit or boat is selected.
Cancel selection on right-click
src/client/InputHandler.ts, tests/InputHandler.test.ts
Right-click deselects an active unit and suppresses the context menu; tests cover both selected and unselected states.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: small-fix

Poem

Right-click taps the sea,
A warship lets selection flee,
No menu appears,
The course now clears,
Smooth sailing follows happily.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: right-click now cancels selection instead of opening the menu.
Description check ✅ Passed The description matches the change and explains the right-click cancellation fix and added tests.
Linked Issues check ✅ Passed The code and tests satisfy #4692 by cancelling selected boat or warship selection on right-click and keeping the menu for no selection.
Out of Scope Changes check ✅ Passed The changes stay within InputHandler and its regression tests, with no unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/InputHandler.test.ts`:
- Around line 1142-1151: Update the warship right-click test around rightClick()
and emittedTypes() to inspect the emitted UnitSelectionEvent payload, asserting
that unit is null and isSelected is false. Keep the existing assertions that a
deselection event is emitted and no ContextMenuEvent is emitted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8aba240b-da71-4a1c-87f8-747ac99c5fa4

📥 Commits

Reviewing files that changed from the base of the PR and between edbeb69 and e238ff9.

📒 Files selected for processing (2)
  • src/client/InputHandler.ts
  • tests/InputHandler.test.ts

Comment thread tests/InputHandler.test.ts Resolved
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jul 26, 2026
…e menu

With a warship/boat selected, right-clicking opened the radial context
menu instead of cancelling the selection: InputHandler.onContextMenu
emitted ContextMenuEvent unconditionally, with no branch for an active
selection, and the EventBus has no way for another listener to suppress
the menu.

Mirror the existing ghost-structure cancel in onContextMenu: track
whether any unit is selected (InputHandler already listens to
UnitSelectionEvent for the cursor) and, on right-click, cancel the
selection and return before emitting ContextMenuEvent. Add regression
tests covering both the selected (cancel, no menu) and unselected
(menu opens) cases.

Resolves openfrontio#4692

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eastwoodgrant
eastwoodgrant force-pushed the fix/4692-cancel-warship-selection branch from e238ff9 to b65c432 Compare July 26, 2026 16:39
Address review feedback: verify the emitted UnitSelectionEvent is
specifically a deselection (unit === null, isSelected === false) rather
than just any UnitSelectionEvent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eastwoodgrant

Copy link
Copy Markdown
Contributor Author

Good catch — updated the test to assert the emitted event is specifically a deselection (unit === null, isSelected === false), not just any UnitSelectionEvent. Pushed in b155f68.

@iiamlewis

Copy link
Copy Markdown
Contributor

@eastwoodgrant (via Discord):

needs milestone

@evanpelle evanpelle added this to the v33 milestone Jul 27, 2026
@github-project-automation github-project-automation Bot moved this from Development to Final Review in OpenFront Release Management Jul 27, 2026
@evanpelle
evanpelle merged commit 8a0efab into openfrontio:main Jul 27, 2026
9 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Final Review to Complete in OpenFront Release Management Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Cannot cancel selection of warship/boat

3 participants