mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Scroll directly to comment position (#28349)
* Scroll directly to comment position * Only use EditorView.scrollIntoView when the target position is outside the viewport * Always listen for editor:scroll-position-restored (#28352) GitOrigin-RevId: 2da23b05ddd4ddbd2631c1da5b27dbef4757c86d
This commit is contained in:
@@ -402,20 +402,31 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
||||
})
|
||||
)
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user