From c80240e7f802ed4b00dd3906bf346f8d177800dc Mon Sep 17 00:00:00 2001 From: Suzanne Soy Date: Tue, 21 Nov 2023 17:56:32 +0000 Subject: [PATCH] Fixed scrolling issue --- git-tutorial.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/git-tutorial.js b/git-tutorial.js index 2b86547..55ecf7f 100644 --- a/git-tutorial.js +++ b/git-tutorial.js @@ -1177,7 +1177,12 @@ function ___scrollToLine(editor, line) { editor.addLineClass(line, 'background', 'scrolled-to-line'); var editorOffset = ___getOffset(editor.getScrollerElement()).top; var lineOffset = editor.charCoords({line: line, ch: 0}, "local").top; - document.body.scrollTo(0, editorOffset + lineOffset - window.innerHeight/2); + var toOffset = editorOffset + lineOffset - window.innerHeight/2; + document.body.parentElement.scrollTo(0, toOffset); + if (document.body.parentElement.scrollTop == 0) { + // depending on the CSS, the scrollbar can belong to the HTML element or to the body element. + document.body.scrollTo(0, toOffset); + } } function ___toCodeMirror(ta) { var editor = CodeMirror.fromTextArea(ta, {