Fix mobile capture tap handling (Issue #52)#53
Merged
ysgrProgramming merged 1 commit intoNov 27, 2025
Conversation
- Remove selection logic from handleTouchStart to prevent overwriting selectedSquare - Let handleTouchEnd -> handleSquareClick handle selection and capture logic - Add touchStartSquare state to track which square was touched - Add regression tests for mobile capture tap handling This fixes the issue where tapping an opponent piece after selecting your own piece would re-select the opponent piece instead of executing the capture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Issue #52: On touch devices, tapping an opponent piece to capture fails because
handleTouchStartoverwritesselectedSquareimmediately, causinghandleSquareClickinhandleTouchEndto treat the tap as selecting the destination rather than executing the move.Changes
handleTouchStartto prevent overwritingselectedSquaretouchStartSquarestate to track which square was touchedhandleTouchEnd->handleSquareClickhandle selection and capture logicTesting
Self-Walkthrough
Requirements Mapping
Requirement: Update touch handling so that tapping an opponent piece after selecting your own piece triggers
handleMoveAttempt(capture) instead of re-selecting.handleTouchStart. NowhandleTouchEndcallshandleSquareClickdirectly, which checks ifselectedSquareis set and the tapped square has an opponent piece, then callshandleMoveAttempt.Requirement: Ensure taps that start on an opponent piece only select it when no source piece is currently selected.
handleSquareClicklogic handles this: ifselectedSquare === nulland the tapped square has a piece, it selects it. IfselectedSquareis already set and the tapped square has an opponent piece, it attempts capture.Requirement: Add regression tests verifying mobile capture flows work for both same-color selection and opponent captures.
ChessBoard.responsive.test.tsx:should capture opponent piece when tapping opponent piece after selecting own pieceshould select opponent piece when tapping opponent piece without prior selectionshould select own piece when tapping own piece without prior selectionshould execute capture move when tapping opponent piece after selecting own pieceRequirement: Verify desktop click/drag behavior remains unchanged.
Logical Basis
The root cause was that
handleTouchStartunconditionally calledsetSelectedSquare(square)when a piece was touched, overwriting any existing selection. This meant that when tapping an opponent piece after selecting your own piece, theselectedSquarewas immediately overwritten beforehandleTouchEndcould process the capture.The solution is to remove selection logic from
handleTouchStartand lethandleTouchEnd->handleSquareClickhandle all selection and capture logic. This ensures that the selection state is consistent whenhandleSquareClickis called, allowing it to correctly determine whether to select, capture, or move.Closes #52