-
Notifications
You must be signed in to change notification settings - Fork 397
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 tree reporter line highlighting #544
Fix tree reporter line highlighting #544
Conversation
42630b3
to
dadc007
Compare
There were two different problems here: - When fetching lines from the file, we could choose a negative start index for the first line to display from the list of lines, resulting in no lines being shown. - When highlighting a line close to the start of the file, we failed to offset the highlighted line by the number of context lines we would have shown but couldn't because we ran out of lines. Signed-off-by: Matt Wozniski <[email protected]>
dadc007
to
ad3ccee
Compare
My test program for making sure the line number handling is now right was:
That made it easy to test both the case where there's not enough lines above the active frame's line to fill out our context and the case where there are (and the case where the active frame's line is close to the end of the file rather than the start, too, but that doesn't need any special handling). |
After fixing the bug where an empty list would be returned if there were not enough lines before the cursor line in the file, another bug was revealed by the test suite: we've been calling `linecache.getlines()` even for the root node. That's only noticeable in the test suite because we mock the return value from that function. In a real run of the tree reporter, we call `linecache.getlines()` with an empty string as the file name, and it always returns an empty list in that case. Still, better to fix this to recognize the root node and not attempt to fetch lines for it at all. Signed-off-by: Matt Wozniski <[email protected]>
This accounts for both the two bugs fixed in the previous two commits, as well as a change in Textual 0.49: the cursor is no longer shown for unfocusable `TextArea` widgets. Signed-off-by: Matt Wozniski <[email protected]>
ad3ccee
to
d6f05d1
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #544 +/- ##
==========================================
+ Coverage 92.55% 92.82% +0.27%
==========================================
Files 91 91
Lines 11304 11119 -185
Branches 1581 2022 +441
==========================================
- Hits 10462 10321 -141
+ Misses 837 798 -39
+ Partials 5 0 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The latest versions of Textual only support Python 3.8 and higher, so differences from the snapshot are expected when running Python 3.7. Signed-off-by: Matt Wozniski <[email protected]>
Update tree reporter snapshots for Textual 0.49 (the TextArea no longer shows a cursor - yay!) and fix two bugs I noticed while looking at the snapshot diff: sometimes we don't show any lines, and sometimes we highlight the wrong line! Whoops.