Skip to content

Commit

Permalink
Merge pull request #4223 from mbaklor/fix-callback-lock
Browse files Browse the repository at this point in the history
fixed entry OnChanged callback in propery lock
  • Loading branch information
Jacalz authored Sep 10, 2023
2 parents 0f0c642 + e47c92b commit d616000
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,13 @@ func (e *Entry) Append(text string) {
provider.insertAt(provider.len(), text)
content := provider.String()
changed := e.updateText(content)
cb := e.OnChanged
e.propertyLock.Unlock()

if changed {
e.Validate()
if e.OnChanged != nil {
e.OnChanged(content)
if cb != nil {
cb(content)
}
}
e.Refresh()
Expand Down Expand Up @@ -668,11 +669,12 @@ func (e *Entry) TypedKey(key *fyne.KeyEvent) {
if e.CursorRow == e.selectRow && e.CursorColumn == e.selectColumn {
e.selecting = false
}
cb := e.OnChanged
e.propertyLock.Unlock()
if changed {
e.Validate()
if e.OnChanged != nil {
e.OnChanged(content)
if cb != nil {
cb(content)
}
}
e.Refresh()
Expand Down Expand Up @@ -845,11 +847,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.RLock()
cb := e.OnChanged
e.propertyLock.RUnlock()
if cb != nil {
cb(e.Text)
}
e.propertyLock.Unlock()
e.Validate()
}

Expand Down Expand Up @@ -1090,11 +1093,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.RLock()
cb := e.OnChanged
e.propertyLock.RUnlock()
if cb != nil {
cb(e.Text)
}
e.propertyLock.Unlock()
e.Validate()
return true
case fyne.KeyReturn, fyne.KeyEnter:
Expand Down

0 comments on commit d616000

Please sign in to comment.