Skip to content

Make Parse work better with floats#2148

Merged
jneem merged 2 commits intolinebender:masterfrom
superfell:parse
Mar 6, 2022
Merged

Make Parse work better with floats#2148
jneem merged 2 commits intolinebender:masterfrom
superfell:parse

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
Member

@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
Member

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