bugfix: only try to go to a line if the line actually exists

This commit is contained in:
John McLear 2021-10-02 15:08:14 +01:00
parent c361df52d2
commit 73a8d593bb

View file

@ -173,13 +173,15 @@ const loadBroadcastJS = (socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
const goToLineNumber = (lineNumber) => { const goToLineNumber = (lineNumber) => {
// Sets the Y scrolling of the browser to go to this line // Sets the Y scrolling of the browser to go to this line
const line = $('#innerdocbody').find(`div:nth-child(${lineNumber + 1})`); const line = $('#innerdocbody').find(`div:nth-child(${lineNumber + 1})`);
const newY = $(line)[0].offsetTop; if (line) {
const ecb = document.getElementById('editorcontainerbox'); const newY = $(line)[0].offsetTop;
// Chrome 55 - 59 bugfix const ecb = document.getElementById('editorcontainerbox');
if (ecb.scrollTo) { // Chrome 55 - 59 bugfix
ecb.scrollTo({top: newY, behavior: 'auto'}); if (ecb.scrollTo) {
} else { ecb.scrollTo({top: newY, behavior: 'auto'});
$('#editorcontainerbox').scrollTop(newY); } else {
$('#editorcontainerbox').scrollTop(newY);
}
} }
}; };