scroll edit

flattentree
filip mertens 11 months ago
parent 0ec979b2ef
commit 0d65e197bc
  1. 16
      libs/remix-ui/workspace/src/lib/components/flat-tree.tsx

@ -3,7 +3,7 @@ import { Popover } from 'react-bootstrap'
import { FileType, WorkspaceElement } from '../types' import { FileType, WorkspaceElement } from '../types'
import { ROOT_PATH } from '../utils/constants' import { ROOT_PATH } from '../utils/constants'
import { getPathIcon } from '@remix-ui/helper'; import { getPathIcon } from '@remix-ui/helper';
import { Virtuoso } from 'react-virtuoso' import { Virtuoso, VirtuosoHandle } from 'react-virtuoso'
import { FlatTreeItemInput } from './flat-tree-item-input'; import { FlatTreeItemInput } from './flat-tree-item-input';
import { FlatTreeDrop } from './flat-tree-drop'; import { FlatTreeDrop } from './flat-tree-drop';
import { getEventTarget } from '../utils/getEventTarget'; import { getEventTarget } from '../utils/getEventTarget';
@ -68,7 +68,7 @@ export const FlatTree = (props: FlatTreeProps) => {
const ref = useRef(null) const ref = useRef(null)
const [size, setSize] = useState(0) const [size, setSize] = useState(0)
const containerRef = useRef<HTMLDivElement>(null) const containerRef = useRef<HTMLDivElement>(null)
const virtuoso = useRef(null) const virtuoso = useRef<VirtuosoHandle>(null)
const isOnScreen = useOnScreen(containerRef) const isOnScreen = useOnScreen(containerRef)
useEffect(() => { useEffect(() => {
@ -193,6 +193,18 @@ export const FlatTree = (props: FlatTreeProps) => {
}, [containerRef.current]) }, [containerRef.current])
useEffect(() => {
if (focusEdit && focusEdit.element) {
const index = flatTree[focusEdit.element] && Object.keys(flatTree).indexOf(focusEdit.element)
flatTree[focusEdit.element] && virtuoso.current.scrollIntoView({
index,
align: 'center'
})
}
}, [focusEdit])
const Row = (index: number) => { const Row = (index: number) => {
const node = Object.keys(flatTree)[index] const node = Object.keys(flatTree)[index]
const file = flatTree[node] const file = flatTree[node]

Loading…
Cancel
Save