Use position zero for start of string in position at #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this is a bug, let me know if it was actually intentional... right now
position_at
counts position zero as being the first character, so getting a string width at position zero returns the width of 1 character. Position 1 will show the width of 2 characters, etcI think position 0 should return a length of zero, to make it more consistent with how String.length/1 works:
The way I discovered this was when working on positioning a cursor, I was using String.length/1 to figure out where to place my cursor - but due to the way position_at currently works (over-estimating the position by one character) moving my cursor back 1 character wasn't achieving the desired effect. With these changes now my cursor works well. Note though that this might end up affecting other people's code, including the existing TextBox component (I haven't checked this I'm just guessing) if they work by depending on the current behaviour