Skip to content

feat: Add move comments functionality with full round-trip support#56

Open
ysgrProgramming wants to merge 1 commit into
mainfrom
feature/kifu-comments
Open

feat: Add move comments functionality with full round-trip support#56
ysgrProgramming wants to merge 1 commit into
mainfrom
feature/kifu-comments

Conversation

@ysgrProgramming

Copy link
Copy Markdown
Owner

Overview

This PR adds move comments functionality to the chess app, allowing users to add, edit, and remove comments for individual moves. Comments are preserved through export/import cycles.

TDD & Lint Verification

  • I have written failing tests (Red) and confirmed make test fails for the new tests.
  • I have implemented code to pass tests (Green) and confirmed make test passes.
  • I have run make lint and fixed all errors.

All 266 tests passing.

Self-Walkthrough (Logical Reasoning)

Requirement (ID) Implementation & Logic Key File/Function
R1: Add comment field to Move Extended Move interface with optional comment?: string field src/lib/types.ts
R2: Update comment via UI Added UPDATE_MOVE_COMMENT action to GameAction and reducer logic src/lib/gameState.ts
R3: Display comments in MoveList Added comment display UI with edit/add buttons in MoveList component src/components/MoveList.tsx
R4: Export comments in kifu Extended movesToText and movesToPGN to include comments in PGN-style {comment} format src/lib/kifuExport.ts
R5: Import comments from kifu Implemented parseKifuText function to parse kifu text and extract comments src/lib/notation.ts
R6: Round-trip support Comments are preserved through export → import cycles src/lib/kifuExport.ts, src/lib/notation.ts
R7: Context API for comments Added handleUpdateMoveComment to GameStateContext src/contexts/GameStateContext.tsx

Decision Log

  • Comment format: Chose PGN-style {comment} format for compatibility with standard chess notation tools.
  • Comment escaping: Implemented escape/unescape logic for special characters ({}, quotes, newlines) in comments.
  • Parsing approach: Used tokenization-based parser instead of complex regex to handle edge cases more reliably.
  • UI design: Comments are displayed inline below moves, with edit/add buttons for each move. Editing uses a textarea with Enter key support.
  • Backward compatibility: Comments are optional, so existing kifu without comments continue to work correctly.

Testing

  • Added comprehensive unit tests for comment functionality in gameState.test.ts
  • Added export/import tests in kifuExport.test.ts and notation.test.ts
  • Added UI component tests in MoveList.test.tsx
  • All tests passing (266 tests total)

Documentation

  • Updated README.md with comment usage examples and feature description
  • Added documentation for kifu import functionality

- Add comment field to Move type (optional string)
- Implement comment update action in gameState reducer
- Add comment export support in kifuExport (PGN-style {comment} format)
- Implement kifu import/parse functionality with comment parsing
- Add comment UI in MoveList component (display, edit, add)
- Add handleUpdateMoveComment API in GameStateContext
- Add comprehensive tests for comment functionality
- Update README with comment usage examples

All tests passing (266 tests). Comments are preserved through export/import cycles.
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.

1 participant