-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Token-aware text wrapping of commit summaries #9931
Conversation
Co-Authored-By: Halit Ogunc <hltognc@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looking good when running through various test cases. ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice improvement! ✨
I've added a comment, otherwise the new logic looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks y'all! |
Closes #9185
Description
As described in #9185 our naive text wrapping efforts implemented in #2575 suffer from a major problem when commit summaries contains links that gets wrapped.
Since the wrapper operates on the raw text of the commit summary before the
Tokenizer
class (used by theRichText
component) has had a chance to work it happily hard wraps in the middle of a url. When theRichText
component then gets a chance to work on it it creates a link out of the link that remains.This was a limitation that was called out in #2575
In reviewing #9259 it became clear that that assumption no longer held true and we needed to look into a robust way of doing wrapping that was Token aware.
In this PR I've made it possible to provide the
RichText
component with a list of tokens as well as a string for the component to tokenize. I've also updated theCommitSummary
to tokenize both the commit summary and the body before providing them to theRichText
component.Finally I've implemented a token-aware wrapper function that hopefully covers most of the many edge-cases involved in doing this type of wrapping. I've set up https://github.com/niik/commit-summary-wrap-tests as a list of commits with weird behaviors that should be accounted for and intend to keep adding commits there as I encounter them.
Screenshots
Here's a few before and afters
Before
After
Here the wrapper takes into account the fact that the link has been resolved as an issue link and thereby shortened to just two characters.
Before
After
Before
This illustrates the main problem described in #9185.
After
While the link is hard-wrapped both parts are clickable and go to the same URL.
Before
Not aware of emojis, splits after 72 characters (counting ':one:` as five characters)
After
Emojis are counted as two regular characters so we're able to fit a lot of them in the commit summary.
Notes
This does not solve (but it doesn't make the situation any worse either) the problem of multibyte unicode characters (native emoji). They can still get wrapped in the middle. I don't intend to address that as part of this PR.
Release notes
Notes: [Fixed] Links are no longer broken when text wrapping needs to take place in commit summaries