Skip to content

fix/FEN import ignores side to move#3117

Merged
veloce merged 2 commits into
lichess-org:mainfrom
MaartenD:fix/FEN-import-ignores-side-to-move
May 6, 2026
Merged

fix/FEN import ignores side to move#3117
veloce merged 2 commits into
lichess-org:mainfrom
MaartenD:fix/FEN-import-ignores-side-to-move

Conversation

@MaartenD

@MaartenD MaartenD commented May 5, 2026

Copy link
Copy Markdown
Contributor

Fix: Board editor FEN paste ignores side to move (and castling rights)

Root cause
loadFen in BoardEditorController only called _updatePosition, which updates piece positions but leaves all other state (sideToPlay, castlingRights, enPassantSquare, etc.) unchanged. Pasting a FEN where black is to move had no effect on the side to play.

Fix
loadFen now distinguishes between two cases:

  • Partial FEN (piece placement only, 1 field): preserves the old behavior, only pieces are updated, castling rights remain in state and are filtered by piece positions via _castlingRightsPart.
  • Full FEN (2+ fields): all fields are read from the parsed FEN, sideToPlay, castlingRights, enPassantSquare, halfmoves, and fullmoves are all updated.

Test added
A new test Pasting FEN with black to move correctly sets side to play was added to test/view/board_editor/board_editor_screen_test.dart. It pastes a full FEN with black to move and verifies that sideToPlay is correctly set to Side.black after the paste.

Note
The FEN parsing logic in loadFen (for the full FEN case) is similar to the inline logic in build(). Should this be extracted into a shared helper method, or is the current duplication acceptable?

In the videos i used this FEN: r1bqkbnr/pppp1ppp/2n5/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 2 3

Bug
https://github.com/user-attachments/assets/28160b2f-c85f-4f4b-8e19-2551a86c6771

Fixed
https://github.com/user-attachments/assets/320e4e4e-9a70-4b14-9ea1-b84b444c5330

Fixes: #3111

setup,
ignoreImpossibleCheck: true,
);
final castlingRights = IMap({

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.

this logic could be factored out in a private method.

final state = container.read(boardEditorControllerProvider(null));
expect(state.sideToPlay, Side.black);
});

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.

Another test would be useful to test the castling rights logic.

@veloce veloce merged commit ce7c880 into lichess-org:main May 6, 2026
1 check passed
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.

FEN import ignores side to move

2 participants