mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 05:03:09 -07:00
scroll to line number
This commit is contained in:
parent
7da109f1a6
commit
d0158c23de
1 changed files with 10 additions and 0 deletions
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue