mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Fix review panel entry focus handler (#21075)
* Fix review panel entry focus handler * dont check position * remove event.target checks * Revert "remove event.target checks" This reverts commit 3f511e47b6922260666c6952b692f6f0a29d5912. GitOrigin-RevId: 9271df9cdb36a040d59a97c88f21d6e923ac0404
This commit is contained in:
parent
94d78e68cd
commit
332e2a38c9
1 changed files with 24 additions and 8 deletions
|
@ -12,6 +12,8 @@ import {
|
|||
} from '@/features/source-editor/extensions/ranges'
|
||||
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'
|
||||
|
||||
export const ReviewPanelEntry: FC<{
|
||||
position: number
|
||||
|
@ -35,7 +37,7 @@ export const ReviewPanelEntry: FC<{
|
|||
}) => {
|
||||
const state = useCodeMirrorStateContext()
|
||||
const view = useCodeMirrorViewContext()
|
||||
const { openDocId } = useEditorManagerContext()
|
||||
const { openDocId, getCurrentDocId } = useEditorManagerContext()
|
||||
const [focused, setFocused] = useState(false)
|
||||
const { setReviewPanelOpen } = useLayoutContext()
|
||||
|
||||
|
@ -50,20 +52,34 @@ export const ReviewPanelEntry: FC<{
|
|||
if (
|
||||
event.target instanceof HTMLButtonElement ||
|
||||
event.target instanceof HTMLLinkElement ||
|
||||
event.target instanceof HTMLTextAreaElement ||
|
||||
event.target instanceof HTMLAnchorElement
|
||||
) {
|
||||
// Don't focus if the click was on a button/link/textarea/anchor as we
|
||||
// don't want to affect the behaviour of the button/link/textarea/anchor
|
||||
// Don't focus if the click was on a button/link/anchor as we
|
||||
// don't want to affect its behaviour
|
||||
return
|
||||
}
|
||||
|
||||
if (selectLineOnFocus) {
|
||||
openDocId(docId, { gotoOffset: position, keepCurrentView: true })
|
||||
}
|
||||
setFocused(true)
|
||||
|
||||
if (!selectLineOnFocus) {
|
||||
return
|
||||
}
|
||||
|
||||
if (getCurrentDocId() !== docId) {
|
||||
const focusIsOnTextarea = event.target instanceof HTMLTextAreaElement
|
||||
if (focusIsOnTextarea === false) {
|
||||
openDocId(docId, { gotoOffset: position, keepCurrentView: true })
|
||||
}
|
||||
} else {
|
||||
setTimeout(() =>
|
||||
view.dispatch({
|
||||
selection: EditorSelection.cursor(position),
|
||||
effects: EditorView.scrollIntoView(position, { y: 'center' }),
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
[selectLineOnFocus, docId, openDocId, position]
|
||||
[getCurrentDocId, docId, selectLineOnFocus, view, position, openDocId]
|
||||
)
|
||||
|
||||
// Clear op highlight on dismount
|
||||
|
|
Loading…
Reference in a new issue