From a2328cd7f0037f402c346cda4b690e07ab9ba818 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sat, 10 Oct 2020 17:57:22 +0200 Subject: [PATCH] timeslider: bugfix: follow pad contents - only goToLineNumber if it exists (#4390) --- src/static/js/broadcast.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js index 0ae71d86..f14bea49 100644 --- a/src/static/js/broadcast.js +++ b/src/static/js/broadcast.js @@ -255,9 +255,15 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro debugLog(e); } - var lineNumber = Changeset.opIterator(Changeset.unpack(changeset).ops).next().lines; + // we want to scroll to the area that is changed before the lines are mutated and we can't go + // to a line that is not there yet + let lineNumber = Changeset.opIterator(Changeset.unpack(changeset).ops).next().lines; if($('#options-followContents').is(":checked") || $('#options-followContents').prop("checked")){ - goToLineNumber(lineNumber); + if(padContents.currentLines.length <= lineNumber){ + goToLineNumber(padContents.currentLines.length-1) + } else { + goToLineNumber(lineNumber); + } } Changeset.mutateTextLines(changeset, padContents);