From 73a8d593bb8efde53409f6d9054b06b23b610bbd Mon Sep 17 00:00:00 2001 From: John McLear Date: Sat, 2 Oct 2021 15:08:14 +0100 Subject: [PATCH] bugfix: only try to go to a line if the line actually exists --- src/static/js/broadcast.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js index 909b6a085..93b80dac3 100644 --- a/src/static/js/broadcast.js +++ b/src/static/js/broadcast.js @@ -173,13 +173,15 @@ const loadBroadcastJS = (socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro const goToLineNumber = (lineNumber) => { // Sets the Y scrolling of the browser to go to this line const line = $('#innerdocbody').find(`div:nth-child(${lineNumber + 1})`); - const newY = $(line)[0].offsetTop; - const ecb = document.getElementById('editorcontainerbox'); - // Chrome 55 - 59 bugfix - if (ecb.scrollTo) { - ecb.scrollTo({top: newY, behavior: 'auto'}); - } else { - $('#editorcontainerbox').scrollTop(newY); + if (line) { + const newY = $(line)[0].offsetTop; + const ecb = document.getElementById('editorcontainerbox'); + // Chrome 55 - 59 bugfix + if (ecb.scrollTo) { + ecb.scrollTo({top: newY, behavior: 'auto'}); + } else { + $('#editorcontainerbox').scrollTop(newY); + } } };