Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions public/assets/js/diff-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,24 @@
attributeFilter: ["data-folded", "data-tree-filtered"],
});
updateFoldLabels();
// GitHub loads the next files while scrolling. Press Forgejo's hidden "Show more" link before the end comes into
// view; its handler swaps in a new #diff-incomplete for each page. A loader still there after a while failed or is
// slow, so it is watched again and retried once in view.
// GitHub loads the next files while scrolling. Press Forgejo's hidden "Show more" link while the end is still four
// screens away, so a page is usually loaded before it is reached; its handler swaps in a new #diff-incomplete for
// each page. A link that is busy with another load is tried again shortly; a loader still there after a while failed
// or is slow, so it is watched again and retried once in view.
const content = document.getElementById("diff-content-container");
if (content && "IntersectionObserver" in window) {
const loader = new IntersectionObserver(
entries => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
loader.unobserve(entry.target);
entry.target.querySelector("#diff-show-more-files:not(.disabled)")?.click();
setTimeout(() => entry.target.isConnected && loader.observe(entry.target), 5000);
const link = entry.target.querySelector("#diff-show-more-files");
const busy = link?.classList.contains("disabled");
if (link && !busy) link.click();
setTimeout(() => entry.target.isConnected && loader.observe(entry.target), busy ? 300 : 5000);
}
},
{ rootMargin: "0px 0px 2000px 0px" }
{ rootMargin: "0px 0px 400% 0px" }
);
const watchIncomplete = () => {
const incomplete = document.getElementById("diff-incomplete");
Expand Down
5 changes: 5 additions & 0 deletions styles/components/issues/pull_review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const mergeButton = `
`;

export default css`
.full.height:has(> .page-content.github-pull-review.files) {
padding-bottom: 0;
}
.page-content.repository.view.issue.github-pull-review {
& > .ui.container {
width: calc(100% - 64px) !important;
Expand All @@ -50,6 +53,8 @@ export default css`
&.files > .ui.container {
width: 100% !important;
max-width: none !important;
/* GitHub's divider between the file tree and the files runs down to the footer. */
margin-bottom: 0 !important;
}
/* GitHub's files tab is full width: title, tabs and diff share a 24px side margin. */
&.files > .ui.container > .issue-title-header,
Expand Down
25 changes: 16 additions & 9 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
selectedItem: '',
};
diffFileInfo = Object.assign(diffFileInfo, diffData);
diffFileInfo.files.push(...diffDataFiles);
// Every page lists all files of the diff, so a loaded page adds only the files not listed yet. Pushing the
// whole list again grew the tree's data with each page and slowed every later page down.
const knownFiles = new Set(diffFileInfo.files.map(file => file.NameHash));
diffFileInfo.files.push(...diffDataFiles.filter(file => !knownFiles.has(file.NameHash)));
window.config.pageData.diffFileInfo = diffFileInfo;
</script>
{{end}}
Expand Down Expand Up @@ -199,16 +202,20 @@
{{end}}

</div>
{{if .DiffMetadata.HasNext}}
{{/* GitHub loads the next files while scrolling: diff-view.js presses the hidden "Show more" link. */}}
<div class="diff-loading-more" id="diff-incomplete" role="status">
<span class="diff-loading-spinner" aria-hidden="true"></span>
<span>{{ctx.Locale.Tr "loading"}}</span>
<a class="tw-hidden" id="diff-show-more-files" data-href="?{{range $i, $f := .FileSelection}}{{if $i}}&{{end}}files={{$f}}{{end}}&diff-page={{len (printf "a%*s" .DiffMetadata.CurrentPage "")}}&file-only=true">{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
</div>
{{end}}
{{end}}
</div>
{{/* Forgejo removes #diff-incomplete and appends the next one to #diff-content-container after every page. The
element before a removed or added last child is restyled with everything inside it, so without this empty
element every page restyled all files loaded so far, and each page loaded slower than the one before. */}}
<div class="diff-content-end" hidden></div>
{{if and (not .DiffNotAvailable) .DiffMetadata.HasNext}}
{{/* GitHub loads the next files while scrolling: diff-view.js presses the hidden "Show more" link. */}}
<div class="diff-loading-more" id="diff-incomplete" role="status">
<span class="diff-loading-spinner" aria-hidden="true"></span>
<span>{{ctx.Locale.Tr "loading"}}</span>
<a class="tw-hidden" id="diff-show-more-files" data-href="?{{range $i, $f := .FileSelection}}{{if $i}}&{{end}}files={{$f}}{{end}}&diff-page={{len (printf "a%*s" .DiffMetadata.CurrentPage "")}}&file-only=true">{{ctx.Locale.Tr "repo.diff.show_more"}}</a>
</div>
{{end}}
</div>
</div>
<script src="{{AssetUrlPrefix}}/js/diff-view.js" defer></script>
Expand Down
Loading