scroll to line number

This commit is contained in:
Alysa Meng 2024-07-22 20:46:43 -07:00
commit d0158c23de

View file

@ -53,6 +53,16 @@ haste_document.prototype.load = function(key, callback, lang) {
highlighted = "<span id='line-" + i + "'>" + highlighted + "</span>"; highlighted = "<span id='line-" + i + "'>" + highlighted + "</span>";
high.value += highlighted + "\n"; 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) { } catch (err) {
// failed highlight, fall back on auto // failed highlight, fall back on auto
high = hljs.highlightAuto(res.data); high = hljs.highlightAuto(res.data);