Skip to content

Commit

Permalink
Fix issue where implicit selection deletion can break text state
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Oct 21, 2022
1 parent ac953b0 commit c531b78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions widget/entry.go
Expand Up @@ -728,7 +728,10 @@ func (e *Entry) TypedRune(r rune) {

// if we've typed a character and we're selecting then replace the selection with the character
if selecting {
cb := e.OnChanged
e.OnChanged = nil // don't propagate this change to binding etc
e.eraseSelection()
e.OnChanged = cb // the change later will then trigger callback
}

e.propertyLock.Lock()
Expand Down
15 changes: 15 additions & 0 deletions widget/entry_test.go
Expand Up @@ -42,6 +42,21 @@ func TestEntry_Binding(t *testing.T) {
assert.Equal(t, "Typed", entry.Text)
}

func TestEntry_Binding_Replace(t *testing.T) {
entry := widget.NewEntry()
str := binding.NewString()
_ = str.Set("Content")
entry.Bind(str)
waitForBinding()
assert.Equal(t, "Content", entry.Text)

typeKeys(entry, fyne.KeyRight, fyne.KeyRight, keyShiftLeftDown, fyne.KeyRight, fyne.KeyRight, keyShiftLeftUp)
assert.Equal(t, "nt", entry.SelectedText())

test.Type(entry, "g")
assert.Equal(t, "Cogent", entry.Text)
}

func TestEntry_Clicked(t *testing.T) {
entry, window := setupImageTest(t, true)
defer teardownImageTest(window)
Expand Down

0 comments on commit c531b78

Please sign in to comment.