From d4acae549c303277bc5233cbcf70647d8a46c5b5 Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Jul 26 2019 11:38:01 +0000 Subject: enhance highlight scrolling logic on file template --- diff --git a/pagure/templates/file.html b/pagure/templates/file.html index b6e7869..45ace13 100644 --- a/pagure/templates/file.html +++ b/pagure/templates/file.html @@ -272,16 +272,19 @@ No content found in this repository $('pre.syntaxhighlightblock code').each(function(i, block) { hljs.highlightBlock(block); hljs.lineNumbersBlock(block); - var cls = "highlighted-line"; - var lines = location.hash.substr(2).split('-').map(function (x) { return parseInt(x, 10) }); - if (! isNaN(lines[0])) - { - $("#_" + lines[0]).get(0).scrollIntoView(); - for (var i = lines[lines.length - 1]; i >= lines[0]; i--) { - $('#_' + i).parent().parent().addClass(cls); - } + }); + + var cls = "highlighted-line"; + var lines = location.hash.substr(2).split('-').map(function (x) { return parseInt(x, 10) }); + if (! isNaN(lines[0])) + { + for (var i = lines[lines.length - 1]; i >= lines[0]; i--) { + $('#_' + i).parent().parent().addClass(cls); } - }) + setTimeout(function(){ + $("#_" + lines[0]).get(0).scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"}); + }, 50); + } });