fix(tui): chapter phase survives trailing-space deletion#15
Merged
Conversation
…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.
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
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, theQueryTypedhandler 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:
JohnJohnJohn 1John1John 10John10JohMarkTesting
reader-reducer.test.tscover the trailing-space deletion and bare-digit suffix cases — all fail before the fix and pass after.src/cli/loading.test.tsand are being fixed in fix(cli): withLoading no-ops when stream is not a TTY #14.1, confirm chapter grid stays visible and highlights chapter 1.