-
Notifications
You must be signed in to change notification settings - Fork 656
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
Floating header in PR files view covers selected line #598
Comments
Hi @maxrothman! The problem is GitHub uses JavaScript to position the element on click. And since we're dealing with table rows, I haven't been able to find any tricks to get the element to scroll into view - see StylishThemes/GitHub-FixedHeader#9 (comment). Do you have any ideas? |
That doesn't appear to be true anymore. I did a little debugging and here's what I found: The event listener triggers the scroll is this one in https://assets-cdn.github.com/assets/frameworks-70361af718ac8e05b3aaf9cf0c4cc8bd.js:
This basically seems like some kind of event dispatcher. After it filters to the node it's looking for, it calls
So it seems they're relying on native browser behavior to scroll the element into view. |
Yeah, it's difficult to read & make sense of minified code. Either way, I wasn't able to find a solution that would allow offsetting the scroll position. |
Here's a thought: most of the tutorials I found about how to solve this issue used a relatively-positioned |
If you do that it distorts the table row and makes it as tall as the |
Hm, you're right. Oh well, custom userscript it is. |
@maxrothman see #612 though for me the annoying portion was fixed, its the same floating header that causes your issue. you can fix your issue also by implementing that code in #612 (comment) |
Yeah, I figured I could disable it, but I don't really want to. I like the sticky behavior, I just also want the line anchors to work properly 🙁 |
Yes, ;) Hows GitHub support nowdays? I rather stick hot needles into my eyes and fillet my own skin than to even consider goin in https://github.com/contact.ever again 👁️ 📌 🔪 ☠️ |
its not perfect but a top position of 30px instead of 39px sort of makes this a non issue. .pull-request-tab-content .diff-view .file-header {
position: sticky !important;
position: -webkit-sticky !important;
top: 30px !important;
z-index: 6 !important;
} The caveat is, if you hit refresh the selected line will be covered again or if you select the same line twice until you select another line. |
Setting the top to And it still doesn't fix anything if you're also using the fixed header userstyle. |
I did say it wasnt perfect, I would move the buttons down tbh, As for using yet another script as a reason not to do this, Im not sure what to say to that considering this sticky behaviour is not even default either. It works for my use case and likely for everyone else who doesnt use that fixed header script, which should also have some similar hack. I vote for one less impinging pestering bug. |
Again not perfect, please adjust to your liking and does not account for non default sticky header styles/scripts, If there is a problem with those its beyond the scope of this issue IMO and they need to be addressed separately. @supports (position: sticky) or (position: -webkit-sticky) {
.pull-request-tab-content .diff-view .file-header {
position: sticky !important;
position: -webkit-sticky !important;
top: 39px !important;
z-index: 6 !important;
}
.pull-request-tab-content .file-header {
height: 39px !important;
}
.pull-request-tab-content .diff-view .file-actions,
.pull-request-tab-content .diff-view .file-info {
margin-top: -2px !important;
}
} The caveats still apply and I dare repeat its not perfect but its MUCH better than as is with just GHD. /me waves fist at prettier-github meddling bot which should wait 5 minutes before fiddling. |
I've tested #690, and it seems like it works pretty well! @Mottie I'm not sure I understand your comment, what other visual changes are caused by this change? I didn't see any visual overlapping. @the-j0k3r perhaps you could make a side-by-side screenshot comparison? |
I have to reopen this due to new information available from #724 (double height file headers) So the issue is found in areas like https://github.com/wpilibsuite/allwpilib/pull/1022/files#diff-b0bc4c1c897b5abdb841f75a8f7896f7R3 when we encounter these extra height file-headers the line selection is lost behind the height of that header. Everything works in normal height lines and #724 is fixed So question is, do we live with this bug and hope its not so common or do we revisit the fix for this issue again or do we just remove the whole block and dammed be sticky file-headers or what. You need to apply 8405aea because that also fixes #724 in this issue area and perhaps to better understand the issue. |
Untested theory: .selected-line {
position: relative;
top: 30px;
display: none;
}
.selected:after {
content: attr(data-line-number);
position: relative;
top: -30px;
} This should move the active line number (which is the link target) 30px below, hide it, and introduce another line number element in the old place. Probably need to tweak styles on the pseudo element but I think this may work and solve this issue reliably. |
I like where your head is at :) Testing this out added that inside/outside the solution code (for good measure) But its a step in right direction whatever is happening is well after the header. |
This works as a pure CSS solution: [id^=diff-].selected-line {
position: relative !important;
top: -120px !important;
left: -10000px !important;
}
[id^=diff-].selected-line:before {
content: attr(data-line-number) !important;
position: absolute !important;
top: 120px !important;
left: 10000px !important;
background: #2e2e2e !important;
color: #7b7b7b !important;
box-sizing: border-box !important;
display: block !important;
padding: 0 10px !important;
width: 100% !important;
} But GitHub's JS is interfering and repositioning the scroll offset on page reload, so I think this is not possible without JS unfortunately. Maybe move the sticky header to it's own userscript and fix it properly there, possibly by disabling GitHub's repositioning thingy. |
Page reloads be dammed, Is it not very unlikely you're chugging away reviewing away and select a line and then hit refresh for the hell of it? If it was accidental refresh, is it a huge deal to find the line again? I dont think either are important deal-breakers and that issue was already present from the get go before any of these fixes. So if it works sod it. :) @supports (position: sticky) or (position: -webkit-sticky) {
.pull-request-tab-content .diff-view .file-header {
position: sticky !important;
position: -webkit-sticky !important;
top: 40px !important;
z-index: 6 !important;
}
[id^=diff-].selected-line {
position: relative !important;
top: -120px !important;
left: -10000px !important;
}
[id^=diff-].selected-line:before {
content: attr(data-line-number) !important;
position: absolute !important;
top: 120px !important;
left: 10000px !important;
background: inherit !important;
color: inherit !important;
box-sizing: border-box !important;
display: block !important;
padding: 0 10px !important;
width: 100% !important;
}
} That works very well the inherited colors also work funnily enough, So I say we go with this revised version. |
Found the actual JS that offsets the scroll: function Xn(e) {
var t = e.ownerDocument;
e.scrollIntoView(),
t.defaultView.scrollBy(0, -Qn(t))
}
function Qn(e) {
Vn();
var t = e.querySelectorAll(".js-sticky-offset-scroll");
return Math.max.apply(Math, le(Array.from(t).map(function(e) {
var t = e.getBoundingClientRect()
, r = t.top
, n = t.height;
return 0 === r ? n : 0
})))
} Basically, they query the height of |
In the PR files view (e.g.
https://github.com/<owner>/<repo>/pull/<number>/files
), when a line has been selected, the floating file header covers the selected line.Steps to reproduce:
https://github.com/<owner>/<repo>/pull/<number>/files#diff-<sha>-L<num>
and the view jumps to the selected line.Expected result:
![screen shot 2018-03-23 at 1 03 43 pm](https://user-images.githubusercontent.com/2607086/37843247-c7d07bca-2e9a-11e8-9975-ac39dfeb049d.png)
![screen shot 2018-03-23 at 1 04 08 pm](https://user-images.githubusercontent.com/2607086/37843262-ce1f3b38-2e9a-11e8-896c-0c415e8b648a.png)
Actual result:
This problem occurs because when the anchor is added to the URL (via a
click
event handler) the view jumps to put the element at the top of the screen. Since the floating file header is also at the top of the screen, it covers the line.I played around with various solutions to this problem, but most of the ones I tried depend on being able to change the height and margin-top of the
:before
pseudo-element, and github is already using it to put the line number before the line.The text was updated successfully, but these errors were encountered: