From 36432ffb5b3fd7009b63a486515e56837eee08bc Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 15 Jan 2026 13:25:18 +0000 Subject: [PATCH] Clamp pos when storing scroll position (#30773) GitOrigin-RevId: b381950e209c18a5fbba07604839b7c3eac90da8 --- .../js/features/source-editor/extensions/scroll-position.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 }) }