-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix off by one error in highlight #649
Conversation
also updated minor version of ahash as 0.8.3 does not compile for me, did not bother separating it into a different commit as its a very small change |
Looking more into it there is something funky with the wrapping. start_index is not correct after the line is built for the first_line_msg |
2aeec9e
to
bd57967
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #649 +/- ##
==========================================
+ Coverage 17.86% 17.87% +0.01%
==========================================
Files 42 42
Lines 5430 5431 +1
==========================================
+ Hits 970 971 +1
Misses 4460 4460 ☔ View full report in Codecov by Sentry. |
I think I know what the issue is. When finding the indices to highlight, the message contains a newline character, which is then removed when splitting the message into multiple lines. This leads to the start_index not matching the highlight index. A solution might be to just strip newlines from the message when trying to find the sections to highlight, or maybe just do a +1 to the start index only when the current line contained a newline. Your solution, if I'm right, would give us an off by one highlight when the message spans more than one line without containing a newline. Let me know if you need any more help with the PR. |
Looking at textwrap docs, wrap() should not include a trailing newline char. |
Sorry I haven't replied yet, busy with IRL stuff. I'll take a look at this when I can. |
Tested between branches, this fix looks to work perfectly. Thanks for the PR! |
I'm afraid this PR breaks the case where the line just overflows onto the next line, without a line break. This is from current git main branch: The full solution needs to check where the newlines are in the message, then increment the start_index at the right time. I can make a PR that fixes this, unless @vesdev wants to do it? Edit: Fixed bad image |
Ah hell I thought I tested that, my bad. Good thing I didn't do a release for it 😅 |
Yea feel free to, the proper fix I think would be using the textwrap output for getting the highlight indices instead of the message payload. Didn't think about break_word 🤔 |
This reverts commit 62f53e4.
before
after
it does not account for the newlines properly
shoutout to mostlymaxi's chat for noticing this