fix: wrap composer input across multiple lines#2
Open
dsilbergleithcu-godaddy wants to merge 1 commit intominghinmatthewlam:mainfrom
Open
fix: wrap composer input across multiple lines#2dsilbergleithcu-godaddy wants to merge 1 commit intominghinmatthewlam:mainfrom
dsilbergleithcu-godaddy wants to merge 1 commit intominghinmatthewlam:mainfrom
Conversation
When a user typed past the terminal width in Read Mode, the input was truncated and the cursor became invisible. The composer now wraps to additional visual rows and the footer grows to fit. - Add wrapInput() that wraps at character boundaries and reports cursorRow/cursorCol, handling the wrap-width boundary and trailing empty-line cases. - Replace fixed FOOTER_LINES=5 with dynamic inputVisualLines so vh() and maxScroll() account for the composer's real height. - Continuation lines get a 2-space indent to align with '> '. - Add focused tests for wrap behavior and cursor placement. Fixes minghinmatthewlam#1
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 #1. In Read Mode, typing past the terminal width truncated the input and hid the cursor. The composer now wraps onto additional visual rows and the footer grows to accommodate it.
Changes
wrapInput(text, cursor, wrapWidth)— character-based wrap that also reports(cursorRow, cursorCol). Handles the two awkward cases:FOOTER_LINES = 5withFOOTER_STATIC_LINES = 4 + inputVisualLines.vh()/maxScroll()now reflect the real viewport so PgUp/PgDn still page correctly.>prompt.vh()is read, so the viewport/footer split is correct on the same frame the input grows or shrinks.I went with character-based wrap rather than word-boundary wrap. It makes cursor mapping exact for any input (including paste, long URLs, CJK) and avoids edge cases around whitespace-only segments. Happy to add word-boundary wrapping on top if you'd prefer — the hooks are all in one function.
Tests
Added
test/wrap-input.test.tswith 9 focused tests (one assertion each) covering: short text, exact width, long wrap, cursor at start, cursor mid-line, cursor at wrap boundary, cursor at end of full text, cursor at end of partial line, empty text. I also did a break-the-code check (inverted the wrap condition) and confirmed 3/9 failed before restoring.Run:
npx tsx --test test/wrap-input.test.tsNot covered