fix(textarea): stop wordLeft from spinning on an empty buffer#974
Open
c-tonneslan wants to merge 1 commit into
Open
fix(textarea): stop wordLeft from spinning on an empty buffer#974c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
textarea.wordLeft has an unconditional for-loop whose only exit is landing on a non-space rune. When the textarea is empty (or all trailing whitespace) characterLeft is a no-op at (0,0) and the break condition col < len(value[row]) is 0 < 0, so the loop spins forever and freezes the Bubble Tea event loop. doWordRight already guards the same way for end-of-text. Add a beginning-of-text check at the top of the loop so the function returns instead of looping. Filed against bubbletea (charmbracelet/ bubbletea#1652) but the code lives here. Regression test triggers WordBackward on an empty textarea inside a goroutine and fails if it doesn't return within 2 seconds. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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.
Filed against bubbletea but lives here: charmbracelet/bubbletea#1652.
`textarea.wordLeft` (the `alt+left` / `alt+b` binding) has an unconditional `for` loop whose only exit is landing on a non-space rune. When the textarea is empty (or all trailing whitespace) `characterLeft` is a no-op at `(0, 0)` and the break condition `col < len(value[row])` is `0 < 0`, so the loop spins forever and freezes the Bubble Tea event loop. `doWordRight` already has the same kind of guard for the end-of-text case.
Added an explicit beginning-of-text check at the top of the loop. If we're already at `(0, 0)`, return early.
Test plan
```
go test ./textarea/...
```
Added `TestWordLeftOnEmptyDoesNotHang` which dispatches `alt+left` on an empty textarea inside a goroutine and fails if the call doesn't return within 2 seconds — without the fix the test hangs until the test framework times out.