Skip to content

Commit

Permalink
Fix issue with wrapping moving cursor too far after backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Feb 18, 2022
1 parent f257a3f commit a147bf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion widget/entry.go
Expand Up @@ -907,7 +907,8 @@ func (e *Entry) rowColFromTextPos(pos int) (row int, col int) {
row++
}
col = pos - b.begin
if canWrap && b.begin == pos && col == 0 && pos != 0 && row < (totalRows-1) {
// if this gap is at `pos` and is a line wrap, increment (safe to access boundary i-1)
if canWrap && b.begin == pos && pos != 0 && provider.rowBoundary(i-1).end == b.begin && row < (totalRows-1) {
row++
}
} else {
Expand Down
18 changes: 16 additions & 2 deletions widget/entry_test.go
Expand Up @@ -512,12 +512,26 @@ func TestEntry_OnKeyDown_Backspace(t *testing.T) {
assert.Equal(t, 0, entry.CursorRow)
assert.Equal(t, 2, entry.CursorColumn)

key := &fyne.KeyEvent{Name: fyne.KeyBackspace}
entry.TypedKey(key)
backspace := &fyne.KeyEvent{Name: fyne.KeyBackspace}
entry.TypedKey(backspace)

assert.Equal(t, "H", entry.Text)
assert.Equal(t, 0, entry.CursorRow)
assert.Equal(t, 1, entry.CursorColumn)

entry = widget.NewMultiLineEntry()
entry.Wrapping = fyne.TextWrapWord
entry.SetText("Line\n2b\n")
down := &fyne.KeyEvent{Name: fyne.KeyDown}
entry.TypedKey(down)
entry.TypedKey(right)
assert.Equal(t, 1, entry.CursorRow)
assert.Equal(t, 1, entry.CursorColumn)

entry.TypedKey(backspace)
assert.Equal(t, "Line\nb\n", entry.Text)
assert.Equal(t, 1, entry.CursorRow)
assert.Equal(t, 0, entry.CursorColumn)
}

func TestEntry_OnKeyDown_BackspaceBeyondText(t *testing.T) {
Expand Down

0 comments on commit a147bf1

Please sign in to comment.