diff --git a/services/web/frontend/js/features/source-editor/extensions/scroll-position.ts b/services/web/frontend/js/features/source-editor/extensions/scroll-position.ts index 3750b3c455..b4966d353f 100644 --- a/services/web/frontend/js/features/source-editor/extensions/scroll-position.ts +++ b/services/web/frontend/js/features/source-editor/extensions/scroll-position.ts @@ -155,7 +155,8 @@ const storeScrollPosition = ( ) => { const key = buildStorageKey(docId) const data = customLocalStorage.getItem(key) - const firstVisibleLine = view.state.doc.lineAt(lineInfo.first.from).number + const pos = Math.min(lineInfo.first.from, view.state.doc.length) + const firstVisibleLine = view.state.doc.lineAt(pos).number customLocalStorage.setItem(key, { ...data, firstVisibleLine }) }