From 8b454f5d241d52c20dd40a365ac0fb4c8f12de1f Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Thu, 20 Feb 2025 11:48:37 +0100 Subject: [PATCH] Change scrollTo behavior when review panel entry is selected (#23720) GitOrigin-RevId: 86fc08f437c49bdf00a9b7d8461b9476f2e9717f --- .../components/review-panel-entry.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx index 4186f7a1a9..744be1e659 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx +++ b/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', + }) + }) } }, [