فهرست منبع

Clamp pos when storing scroll position (#30773)

GitOrigin-RevId: b381950e209c18a5fbba07604839b7c3eac90da8
Alf Eaton 7 ماه پیش
والد
کامیت
36432ffb5b
1فایلهای تغییر یافته به همراه2 افزوده شده و 1 حذف شده
  1. 2 1
      services/web/frontend/js/features/source-editor/extensions/scroll-position.ts

+ 2 - 1
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 })
 }