Repository navigation
Show current filename in sticky pull request header - #99
Conversation
|
@DrewML You could use GFM todo lists in the PR description https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments 😉 |
|
@hkdobrev Good call! Should be knocking out the top 3 in the list when I'm home from work tonight. Still need some help determining what is the most appropriate way to handle the 4th item in that list. |
According to other libraries and websites that do this kind of things, you should only change the file name in the header when the contents of the previous one has gone above the viewport. I think the eyeline library for Discourse.org used to do it like that, but that was years ago. |
| addPatchDiffLinks(); | ||
| } | ||
|
|
||
| if (isPRFiles()) { |
There was a problem hiding this comment.
@DrewML Ultimately you'd use a check which will catch either /pull/<id>/files or <pull/<id>/commits/<sha>.
There was a problem hiding this comment.
You could break the isPR() and isCommit() checks above into smaller pieces using a new one like isPRCommit() and then you could combine checks.
There was a problem hiding this comment.
That's funny - I originally had the POC checking for both, but I had thought late last night that the sticky bar wasn't enabled on commit pages. I just double-checked, and I was wrong :)
There was a problem hiding this comment.
It's enabled on:
- PR files listing
- PR commit pages (new)
It's not enabled on:
- commit pages (default)
- compare views
20f994f to
412e020
Compare
|
All todo items have been completed/pushed. Let me know if anything needs to change, or if I should squash my commits down. |
|
This is related to lines 343-350, 373, and 401-405: Returning the remove event listener in the function const headerEvents = ['scroll', 'resize'];
.
.
.
function bindDiffHeaderListeners() {
headerEvents.forEach(event => window.addEventListener(event, diffHeaderFilename));
}
function unbindDiffHeaderListeners() {
headerEvents.forEach(event => window.removeEventListener(event, diffHeaderFilename));
};
.
.
.
unbindDiffHeaderListeners();
if (isPRFiles() || isPRCommit()) {
bindDiffHeaderListeners();
} |
|
@paulmolluzzo yeah, that's much simpler, and avoids the awkward state in the |
|
I've noticed a buggy behaviour. The first file name is not shown in the header initially, but only after the second file name is shown and then you scroll back up to the first file. If you scroll to the top of the page then and scroll down the first file name is correctly shown from the initial stuck of the header. Here's a GIF demonstrating the buggy behaviour (sorry for the broken colours, it's from the recording): |
|
@hkdobrev Nice catch - I noticed that earlier today when surfing around. I'm pretty sure I know what's causing it - will work on cleaning that up either tonight or tomorrow. |
|
@hkdobrev Fix has been pushed for your reported bug. Let me know if you see any other weirdness. I don't feel super great about the
|
| return false; | ||
| }; | ||
|
|
||
| const reset = function reset() { |
There was a problem hiding this comment.
No need to name the function. It's inferred from the variable name.
|
This introduces a lot of global functions. Maybe we should move all the functions to a separate file inside an IIFE and only expose the two "publicly" used functions under a namespace? diffFileHeader.setup();
diffFileHeader.destroy(); |
| const isRepoRoot = () => location.pathname.replace(/\/$/, '') === `/${ownerName}/${repoName}` || /(\/tree\/)(\w|\d|\.)+(\/$|$)/.test(location.href); | ||
| const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+/.test(location.pathname) || /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname); | ||
| const isPRCommit = () => /^\/[^/]+\/[^/]+\/pull\/\d+\/commits\/[0-9a-f]{5,40}/.test(location.pathname); | ||
| const isCommit = () => { |
There was a problem hiding this comment.
@hkdobrev @paulmolluzzo Unrelated to this PR, but I think our path checking are getting out of control. How about we make a util.js file that exposes these utilities?
util.isRepo();
util.isRepoRoot();
...There was a problem hiding this comment.
I'm OK with this as long as we don't use the name utils, but something more explicit and with one purpose only like urlHelper, urlUtils or just url.
There was a problem hiding this comment.
👍 it'll clean up the code a lot.
There was a problem hiding this comment.
We can do that after this PR is merged :)
There was a problem hiding this comment.
We can do that after this PR is merged :)
👍 Yes, meant after.
|
This looks very good and seems to be working perfectly for me. 👌 |
Sounds good to me - was starting to feel crowded. Will push an update today. |
|
Updates pushed to branch - moved all functionality relating to this PR into a new content script. |
|
@DrewML Can you use arrow functions instead of functions and fix the merge conflict? Looks good to me after that :) |
|
@sindresorhus Done! Also squashed the mile of commits down to 1 for the feature. |
|
@DrewML This is amazing. Superb work! |
|
@DrewML Would you be interested in joining this project as a maintainer? No worries if not though :) |
|
@sindresorhus For sure! I'm in. |
|
Yay! :) |


Ref: Issue #98
Todo: