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

Make Parse work better with floats #2148

Merged
merged 2 commits into from
Mar 6, 2022
Merged

Conversation

superfell
Copy link
Contributor

I was using Parse with TextBox that was lens'd to an f32. The editing behavior is odd, starting from a blank text box you can't type 1.5 because when you get to 1. it gets replaced by 1. This happens because round tripping "1." through parse / to_string results in "1".

This PR updates Parse to skip applying the to_string() in the event that the text already parses to the same value as data. This improves the behavior for f32 and any similar types where there is text lost from a parse/to_string round trip.

Copy link
Collaborator

@jneem jneem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Just one minor typo...

Some(ref x) => {
// Its possible that the current self.state already represents the data value
// in that case we shouldn't clobber the self.state. This helps deal
// with types where parse()/to_string() round trips can loose information
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@jneem jneem merged commit 21b3308 into linebender:master Mar 6, 2022
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
This PR updates Parse to skip applying the to_string() in the event that the text already parses to the same value as data. This improves the behavior for f32 and any similar types where there is text lost from a parse/to_string round trip.
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
This PR updates Parse to skip applying the to_string() in the event that the text already parses to the same value as data. This improves the behavior for f32 and any similar types where there is text lost from a parse/to_string round trip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants