Merge "Improve smooth scroll to section with visual section editing on desktop"

This commit is contained in:
jenkins-bot 2022-11-06 22:53:44 +00:00 committed by Gerrit Code Review
commit 2b5aeaf649

View file

@ -463,11 +463,12 @@
var offset = 0;
var enableVisualSectionEditing = mw.config.get( 'wgVisualEditorConfig' ).enableVisualSectionEditing;
if ( enableVisualSectionEditing === true || enableVisualSectionEditing === 'desktop' ) {
// Heading will jump to the top of the page in visual section editing
// Heading will jump to the top of the page in visual section editing.
// This measurement already includes the height of $toolbarPlaceholder.
offset = $( '#mw-content-text' ).offset().top;
} else {
// Align with top of heading margin. Doesn't apply in visual section editing as the margin collapses.
offset = parseInt( $heading.css( 'margin-top' ) );
offset = parseInt( $heading.css( 'margin-top' ) ) + $toolbarPlaceholder.outerHeight();
}
// Support for CSS `scroll-behavior: smooth;` and JS `window.scroll( { behavior: 'smooth' } )`
@ -475,7 +476,7 @@
// * https://caniuse.com/css-scroll-behavior
// * https://caniuse.com/mdn-api_window_scroll_options_behavior_parameter
var supportsSmoothScroll = 'scrollBehavior' in document.documentElement.style;
var newScrollTop = $heading.offset().top - offset - $toolbarPlaceholder.outerHeight();
var newScrollTop = $heading.offset().top - offset;
if ( supportsSmoothScroll ) {
window.scroll( {
top: newScrollTop,