Skip to content

fix(tui): chapter phase survives trailing-space deletion#15

Merged
ivanmaierg merged 1 commit into
mainfrom
fix/chapter-phase-edits-survive
May 13, 2026
Merged

fix(tui): chapter phase survives trailing-space deletion#15
ivanmaierg merged 1 commit into
mainfrom
fix/chapter-phase-edits-survive

Conversation

@ivanmaierg

Copy link
Copy Markdown
Owner

Summary

After picking a book from the palette, the user reported the chapter grid sometimes disappeared and typing a digit afterwards failed to highlight the chapter. Reproducing: pick John → backspace once → type 1 → no chapter menu, no highlight.

Root cause

In src/tui/reader/reader-reducer.ts, the QueryTyped handler required the new query to start with \${displayName} `— note the **trailing space**. Picking a book sets the query to"John ", which matches. But a single backspace produces "John"(no trailing space), which fails the check. The reducer then falls into the book-phase branch, clearsbookChosen, and re-runs book suggestions. Typing "1"next produces"John1"`, which also fails the check (still no space). User is stuck in book phase with no chapter grid.

Fix

The chapter-phase prefix check now accepts the book name with empty rest, leading space, or leading digit. Digit decoding accepts an optional space between the book name and the chapter number, so:

Query Behavior
John Stay in chapter phase, no highlight change
John Stay in chapter phase (unchanged)
John 1 Stay in chapter phase, highlight chapter 1
John1 Stay in chapter phase, highlight chapter 1 (new)
John 10 Stay in chapter phase, highlight chapter 10
John10 Stay in chapter phase, highlight chapter 10 (new)
Joh Drop to book phase (no longer prefix-match)
Mark Drop to book phase (different book)

Testing

  • 3 new tests in reader-reducer.test.ts cover the trailing-space deletion and bare-digit suffix cases — all fail before the fix and pass after.
  • Full suite: 238/240 pass. The remaining 2 failures are pre-existing in src/cli/loading.test.ts and are being fixed in fix(cli): withLoading no-ops when stream is not a TTY #14.
  • Manual TUI verification recommended: pick John, backspace, type 1, confirm chapter grid stays visible and highlights chapter 1.

…it suffix

Picking a book sets the query to '<Book> ' (with trailing space). The previous
QueryTyped check required that exact prefix to stay in chapter phase, so a
single backspace dropped the chapter grid and re-ran book suggestions. Typing
'1' afterwards landed in book phase with no chapter menu.

The new check accepts the book name with any of: empty rest, leading space, or
leading digit. Digit decoding now allows an optional space between the book name
and chapter number, so 'John1' highlights chapter 1 just like 'John 1' does.
@ivanmaierg ivanmaierg merged commit 2b9080d into main May 13, 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.

1 participant