diff --git a/static/application.js b/static/application.js index 8aef747..ce6c741 100644 --- a/static/application.js +++ b/static/application.js @@ -53,6 +53,16 @@ haste_document.prototype.load = function(key, callback, lang) { highlighted = "" + highlighted + ""; high.value += highlighted + "\n"; } + // scroll to position in document after ensuring components have had time to render + setTimeout(function() { + // show current line and the one before it + if (selectedLines.startLine >= 3) { + document.body.scrollTo(0, $("#line-" + (selectedLines.startLine - 2)).offset().top) + } else { + // if lines 1-2, go to top of file + document.body.scrollTop(0); + } + }, 0); } catch (err) { // failed highlight, fall back on auto high = hljs.highlightAuto(res.data);