Skip to content

binding.String===>Quick refresh *b.val will appear with new data reset by a call to OnChange #3774

Closed
@MrWen

Description

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

// updateText updates the internal text to the given value
func (e *Entry) updateText(text string) {
	var callback func(string)
	e.setFieldsAndRefresh(func() {
		changed := e.Text != text
		e.Text = text
		e.syncSegments()
		e.text.updateRowBounds()

		if e.Text != "" {
			e.dirty = true
		}

		if changed {
			callback = e.OnChanged
		}
	})

	e.Validate()

	if callback != nil {
		callback(text)
	}
}

func (e *Entry) writeData(data binding.DataItem) {
	if data == nil {
		return
	}
	textTarget, ok := data.(binding.String)
	if !ok {
		return
	}
	curValue, err := textTarget.Get()
	if err == nil && curValue == e.Text {
		e.conversionError = nil
		return
	}
	e.conversionError = textTarget.Set(e.Text)
}

How to reproduce

Because refreshing Entry and Set are asynchronous operations。

Quick call String.Set。 Old data overwrites new data when writeData is executed。

Screenshots

No response

Example code

binding := binding.NewString()
entry := widget.NewMultiLineEntry()
entry.Bind(binding)

go func() {
var num int
 for {
str :=fmt.Sprintf("%d", num)
binding.Set(str)
}
}

Fyne version

2.3.2

Go compiler version

1.20

Operating system and version

Window11

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions