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
4 changes: 2 additions & 2 deletions textarea/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (m *Model) setCursorLineRelative(delta int) {

offset := 0
for offset < charOffset {
if m.row >= len(m.value) || m.col >= len(m.value[m.row]) || offset >= nli.CharWidth-1 {
if m.row >= len(m.value) || m.col >= len(m.value[m.row]) || offset >= nli.CharWidth {
break
}
offset += rw.RuneWidth(m.value[m.row][m.col])
Expand Down Expand Up @@ -1849,7 +1849,7 @@ func wrap(runes []rune, width int) [][]rune {
}
}

if uniseg.StringWidth(string(lines[row]))+uniseg.StringWidth(string(word))+spaces >= width {
if uniseg.StringWidth(string(lines[row]))+uniseg.StringWidth(string(word))+spaces > width {
lines = append(lines, []rune{})
lines[row+1] = append(lines[row+1], word...)
// We add an extra space at the end of the line to account for the
Expand Down
66 changes: 48 additions & 18 deletions textarea/textarea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 1,
cursorCol: 0,
cursorRow: 0,
cursorCol: 4,
},
},
{
Expand Down Expand Up @@ -814,8 +814,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 1,
cursorCol: 0,
cursorRow: 0,
cursorCol: 4,
},
},
{
Expand Down Expand Up @@ -861,8 +861,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 3,
cursorCol: 0,
cursorRow: 2,
cursorCol: 1,
},
},
{
Expand All @@ -884,8 +884,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 3,
cursorCol: 0,
cursorRow: 2,
cursorCol: 1,
},
},
{
Expand All @@ -908,8 +908,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 3,
cursorCol: 0,
cursorRow: 2,
cursorCol: 1,
},
},
{
Expand All @@ -933,8 +933,8 @@ func TestView(t *testing.T) {


`),
cursorRow: 3,
cursorCol: 0,
cursorRow: 2,
cursorCol: 1,
},
},
{
Expand Down Expand Up @@ -1004,8 +1004,8 @@ func TestView(t *testing.T) {
>
>
`),
cursorRow: 1,
cursorCol: 0,
cursorRow: 0,
cursorCol: 4,
},
},
{
Expand Down Expand Up @@ -1118,8 +1118,8 @@ func TestView(t *testing.T) {
│> │
└──────────┘
`),
cursorRow: 1,
cursorCol: 0,
cursorRow: 0,
cursorCol: 4,
},
},
{
Expand Down Expand Up @@ -1241,8 +1241,8 @@ func TestView(t *testing.T) {
│> │
└──────────┘
`),
cursorRow: 1,
cursorCol: 0,
cursorRow: 0,
cursorCol: 8,
},
},
{
Expand Down Expand Up @@ -2403,6 +2403,36 @@ func newTextArea() Model {
return textarea
}

func TestWrapExactWidthNoPhantomLine(t *testing.T) {
const width = 10
input := []rune("0123456789")

lines := wrap(input, width)
if len(lines) > 1 {
for i, line := range lines {
if i > 0 && len(strings.TrimSpace(string(line))) == 0 {
t.Fatalf("phantom wrap line at index %d: %#v", i, lines)
}
}
}
}

func TestCursorDownPastExactWidthLine(t *testing.T) {
textarea := newTextArea()
textarea.SetWidth(20)

line1 := strings.Repeat("x", 20)
textarea.SetValue(line1 + "\nsecond")
textarea.row = 0
textarea.col = len(line1)
textarea.lastCharOffset = textarea.LineInfo().CharOffset

textarea.CursorDown()
if textarea.row != 1 {
t.Fatalf("row %d want 1 after moving down from a full-width line", textarea.row)
}
}

func keyPress(key rune) tea.Msg {
return tea.KeyPressMsg{Code: key, Text: string(key)}
}
Expand Down