فهرست منبع

Change scrollTo behavior when review panel entry is selected (#23720)

GitOrigin-RevId: 86fc08f437c49bdf00a9b7d8461b9476f2e9717f
Domagoj Kriskovic 1 سال پیش
والد
کامیت
725db44392
1فایلهای تغییر یافته به همراه10 افزوده شده و 4 حذف شده
  1. 10 4
      services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx

+ 10 - 4
services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx

@@ -13,7 +13,6 @@ import {
 import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
 import { useLayoutContext } from '@/shared/context/layout-context'
 import { EditorSelection } from '@codemirror/state'
-import { EditorView } from '@codemirror/view'
 import MaterialIcon from '@/shared/components/material-icon'
 import { OFFSET_FOR_ENTRIES_ABOVE } from '../utils/position-items'
 
@@ -92,12 +91,19 @@ export const ReviewPanelEntry: FC<{
       if (getCurrentDocumentId() !== docId) {
         openDocWithId(docId, { gotoOffset: position, keepCurrentView: true })
       } else {
-        setTimeout(() =>
+        setTimeout(() => {
           view.dispatch({
             selection: EditorSelection.cursor(position),
-            effects: EditorView.scrollIntoView(position, { y: 'center' }),
           })
-        )
+
+          // scroll to line (centered)
+          const blockInfo = view.lineBlockAt(position)
+          const editorHeight = view.scrollDOM.getBoundingClientRect().height
+          view.scrollDOM.scrollTo({
+            top: blockInfo.top - editorHeight / 2 + blockInfo.height,
+            behavior: 'smooth',
+          })
+        })
       }
     },
     [