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:
Domagoj Kriskovic 2024-10-21 10:57:45 +02:00 committed by Copybot
parent 94d78e68cd
commit 332e2a38c9

View file

@ -12,6 +12,8 @@ import {
} from '@/features/source-editor/extensions/ranges' } from '@/features/source-editor/extensions/ranges'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context' import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
import { useLayoutContext } from '@/shared/context/layout-context' import { useLayoutContext } from '@/shared/context/layout-context'
import { EditorSelection } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
export const ReviewPanelEntry: FC<{ export const ReviewPanelEntry: FC<{
position: number position: number
@ -35,7 +37,7 @@ export const ReviewPanelEntry: FC<{
}) => { }) => {
const state = useCodeMirrorStateContext() const state = useCodeMirrorStateContext()
const view = useCodeMirrorViewContext() const view = useCodeMirrorViewContext()
const { openDocId } = useEditorManagerContext() const { openDocId, getCurrentDocId } = useEditorManagerContext()
const [focused, setFocused] = useState(false) const [focused, setFocused] = useState(false)
const { setReviewPanelOpen } = useLayoutContext() const { setReviewPanelOpen } = useLayoutContext()
@ -50,20 +52,34 @@ export const ReviewPanelEntry: FC<{
if ( if (
event.target instanceof HTMLButtonElement || event.target instanceof HTMLButtonElement ||
event.target instanceof HTMLLinkElement || event.target instanceof HTMLLinkElement ||
event.target instanceof HTMLTextAreaElement ||
event.target instanceof HTMLAnchorElement event.target instanceof HTMLAnchorElement
) { ) {
// Don't focus if the click was on a button/link/textarea/anchor as we // Don't focus if the click was on a button/link/anchor as we
// don't want to affect the behaviour of the button/link/textarea/anchor // don't want to affect its behaviour
return return
} }
if (selectLineOnFocus) { setFocused(true)
if (!selectLineOnFocus) {
return
}
if (getCurrentDocId() !== docId) {
const focusIsOnTextarea = event.target instanceof HTMLTextAreaElement
if (focusIsOnTextarea === false) {
openDocId(docId, { gotoOffset: position, keepCurrentView: true }) openDocId(docId, { gotoOffset: position, keepCurrentView: true })
} }
setFocused(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 // Clear op highlight on dismount