-
Notifications
You must be signed in to change notification settings - Fork 30
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
[Disucssion] handling the "middle" truncation option #93
Comments
+1 to add a comment. Apparently the docs says nothing about this case: And they are not using external deps: https://github.com/patternfly/patternfly-react/blob/main/packages/react-core/src/components/Truncate/Truncate.tsx#L46 |
Right, I am not sure how JavaScript handles Unicode and UTF-8, so I am not sure this can be compared. In Rust, you have "characters", but they are more like "technical" characters. Not “user-perceived characters” (aka grapheme clusters). Also see: https://unicode.org/reports/tr29/ and maybe https://stackoverflow.com/questions/58770462/how-to-iterate-over-unicode-grapheme-clusters-in-rust Now it gets even more complicated, strings are indexed by bytes (not characters). So The current implementation is pretty naive, and just looks for the next location which can he split, based on the byte index. That's a rather quick operation. Assuming Latin 1, most likely is a hit at the first attempt. Otherwise, it takes just a few tries more. The downside is that it might be horribly wrong. Having mostly non Latin1 characters, the byte index doesn't work well. Still, it's quick. Searching for the x-th characters from the end of a string, is a terribly imperforment operation. As one needs to count all "characters" from the beginning of the string. And even then, one would actually need to count all "grapheme clusters" from the start of a string. Maybe it's just better to drop this use case. Then again the current thing is better than not having it. |
Just documented the current impl: 1dccf8a |
Thanks for clarification. I was basically comparing
For a quick info from https://exploringjs.com/impatient-js/ch_strings.html#atoms-of-text
I found this table where apparently firefox is not supporting yet. And the 15 million downloads from this library graphemer are also related to the dependents
Thanks for the links, in a comment a person shared that rust was supporting it on the stdlib, in the past. so yeah now I got the in this case, the comment to be added should be "Warning: this might be horribly wrong !" 😄
yeah I agree, a product/project |
I think the comment is sufficient. It would also be worth adding a link to this issue so that the discussion is easily accessible. I also don't think the implementation needs fixing. If someone is using graphemes that need a lot of bytes, then you will always have a few less of those at the end compared to if everything was ASCII, i.e. visually "more" is truncated - truncating less might be problematic but that will never happen. The behavior is documented now so it is easy to investigate why this is happening if someone stumbles upon it. In the (unlikely) event that someone urgently needs the amount of grapheme clusters to be correct at the end of the string, you could maybe think about opting in to a feature. |
Aside from PRs welcome … one can still manually create the |
Also, amount of characters is a very inaccurate way of measuring how much text you want to keep. 10 "i"s is a lot shorter than 10 "m"s and graphemes could be much much wider again. |
That's why I am just using the |
Continuing from patternfly-yew/patternfly-yew-quickstart#36 (comment):
The text was updated successfully, but these errors were encountered: