Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call OnChange with every updateText, fixes #4117 #4121

Merged
merged 6 commits into from
Aug 20, 2023
Merged
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
30 changes: 28 additions & 2 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,16 @@ func (e *Entry) Append(text string) {
e.propertyLock.Lock()
provider := e.textProvider()
provider.insertAt(provider.len(), text)
e.updateText(provider.String())
content := provider.String()
changed := e.updateText(content)
e.propertyLock.Unlock()

if changed {
e.Validate()
if e.OnChanged != nil {
e.OnChanged(content)
}
}
e.Refresh()
}

Expand Down Expand Up @@ -658,11 +665,18 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) {
}

e.propertyLock.Lock()
e.updateText(provider.String())
content := provider.String()
changed := e.updateText(content)
if e.CursorRow == e.selectRow && e.CursorColumn == e.selectColumn {
e.selecting = false
}
e.propertyLock.Unlock()
if changed {
e.Validate()
if e.OnChanged != nil {
e.OnChanged(content)
}
}
e.Refresh()
}

Expand Down Expand Up @@ -817,6 +831,12 @@ func (e *Entry) cutToClipboard(clipboard fyne.Clipboard) {

e.copyToClipboard(clipboard)
e.setFieldsAndRefresh(e.eraseSelection)
e.propertyLock.Lock()
if e.OnChanged != nil {
e.OnChanged(e.Text)
}
e.propertyLock.Unlock()
e.Validate()
}

// eraseSelection removes the current selected region and moves the cursor
Expand Down Expand Up @@ -1033,6 +1053,12 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool {
case fyne.KeyBackspace, fyne.KeyDelete:
// clears the selection -- return handled
e.setFieldsAndRefresh(e.eraseSelection)
e.propertyLock.Lock()
if e.OnChanged != nil {
e.OnChanged(e.Text)
}
e.propertyLock.Unlock()
e.Validate()
return true
case fyne.KeyReturn, fyne.KeyEnter:
if e.MultiLine {
Expand Down
9 changes: 9 additions & 0 deletions widget/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ func TestEntry_Notify(t *testing.T) {
entry.SetText("Test")

assert.True(t, changed)

changed = false
entry.TypedKey(&fyne.KeyEvent{Name: fyne.KeyDelete})
assert.True(t, changed)

changed = false
entry.CursorColumn = 1
entry.TypedKey(&fyne.KeyEvent{Name: fyne.KeyBackspace})
assert.True(t, changed)
}

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