Skip to content

Improve scroll behavior when folding files on pull request "files changed" tab #23604

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

Closed
wants to merge 20 commits into from
Closed
Changes from 18 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
10 changes: 10 additions & 0 deletions web_src/js/features/file-fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import {svg} from '../svg.js';
// The file content box is the box that should be hidden or shown, especially intended for components having the 'file-content' class.
//
export function setFileFolding(fileContentBox, foldArrow, newFold) {
const diffFileHeader = fileContentBox.querySelector('.diff-file-header');
foldArrow.innerHTML = svg(`octicon-chevron-${newFold ? 'right' : 'down'}`, 18);
fileContentBox.setAttribute('data-folded', newFold);
// scroll position needs to be adjusted only when folding the file
// and scrollY is greater than current file header's offsetTop
if (newFold && window.scrollY > diffFileHeader.offsetTop) {
// Scroll to current file header
window.scrollTo({
top: fileContentBox.offsetTop - document.querySelector('.diff-detail-box').offsetHeight,
behavior: 'instant'
});
}
}

// Like `setFileFolding`, except that it automatically inverts the current file folding state.
Expand Down