diff --git a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx index fcc430dcdb..fa6c3f34eb 100644 --- a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx @@ -402,20 +402,31 @@ export const EditorManagerProvider: FC = ({ }) ) if (hasGotoLine(options)) { - window.setTimeout(() => jumpToLine(options)) + const jump = () => jumpToLine(options) - // Jump to the line again after a stored scroll position has been restored if (isNewDoc) { - window.addEventListener( - 'editor:scroll-position-restored', - () => jumpToLine(options), - { once: true } - ) + // Jump to the line after a stored scroll position has been restored + window.addEventListener('editor:scroll-position-restored', jump, { + once: true, + }) + } else { + // Jump directly to the line + jump() } } else if (hasGotoOffset(options)) { - window.setTimeout(() => { + const jump = () => { eventEmitter.emit('editor:gotoOffset', options) - }) + } + + if (isNewDoc) { + // Jump to the offset after a stored scroll position has been restored + window.addEventListener('editor:scroll-position-restored', jump, { + once: true, + }) + } else { + // Jump directly to the offset + jump() + } } resolve(doc) diff --git a/services/web/frontend/js/features/review-panel/components/review-panel-entry.tsx b/services/web/frontend/js/features/review-panel/components/review-panel-entry.tsx index 3576b7b542..afe025dbae 100644 --- a/services/web/frontend/js/features/review-panel/components/review-panel-entry.tsx +++ b/services/web/frontend/js/features/review-panel/components/review-panel-entry.tsx @@ -15,6 +15,7 @@ import { EditorSelection } from '@codemirror/state' import { OFFSET_FOR_ENTRIES_ABOVE } from '../utils/position-items' import useReviewPanelLayout from '../hooks/use-review-panel-layout' import { EntryIndicator } from './review-panel-entry-indicator' +import { EditorView } from '@codemirror/view' export const ReviewPanelEntry: FC< React.PropsWithChildren<{ @@ -86,9 +87,22 @@ export const ReviewPanelEntry: FC< openDocWithId(docId, { gotoOffset: position, keepCurrentView: true }) } else { setTimeout(() => { - view.dispatch({ - selection: EditorSelection.cursor(position), - }) + const selection = EditorSelection.cursor(position) + + // if the position is outside the viewport, so could be estimated, + // use EditorView.scrollIntoView (accurate, not smooth) + if (position < view.viewport.from || view.viewport.to < position) { + view.dispatch({ + selection, + effects: EditorView.scrollIntoView(selection, { y: 'center' }), + }) + return + } + + // if the position is inside the viewport, so accurate, + // use scrollDOM.scrollTo (smooth) + + view.dispatch({ selection }) // scroll to line (centered) const blockInfo = view.lineBlockAt(position)