Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,9 @@ func (m *Model) wordLeft() {
if m.col < len(m.value[m.row]) && !unicode.IsSpace(m.value[m.row][m.col]) {
break
}
if m.col == 0 && m.row == 0 {
break
}
}

for m.col > 0 {
Expand Down
22 changes: 22 additions & 0 deletions textarea/textarea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"testing"
"time"
"unicode"

tea "charm.land/bubbletea/v2"
Expand Down Expand Up @@ -2429,3 +2430,24 @@ func stripString(str string) string {

return strings.Join(lines, "\n")
}

func TestWordLeftInfiniteLoopRepro(t *testing.T) {
m := New()
m.SetValue(" hello")
m.col = 0
m.row = 0

done := make(chan struct{})
go func() {
m.wordLeft()
close(done)
}()

select {
case <-done:
t.Log("wordLeft finished")
case <-time.After(2 * time.Second):
t.Fatal("wordLeft timed out (likely infinite loop)")
}
}