Skip to content

Commit 89efc64

Browse files
committed
feat: add scroll to selected block in the Tree component
1 parent 034625f commit 89efc64

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

editor-v2/containers/Tree/TreeItem.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ export const Item = ({
4040
const [isDragging, setIsDragging] = React.useState(false);
4141
const [isDragOver, setIsDragOver] = React.useState(false);
4242
const [mouseDownPos, setMouseDownPos] = React.useState<{x: number; y: number} | null>(null);
43+
const itemRef = React.useRef<HTMLDivElement>(null);
44+
45+
// Scroll into view when selected
46+
React.useEffect(() => {
47+
if (selected && itemRef.current) {
48+
itemRef.current.scrollIntoView({
49+
behavior: 'smooth',
50+
block: 'nearest',
51+
});
52+
}
53+
}, [selected]);
4354

4455
const handleCopy = React.useCallback(() => {
4556
onCopy(path);
@@ -182,6 +193,7 @@ export const Item = ({
182193

183194
return (
184195
<Card
196+
ref={itemRef}
185197
className={b({
186198
selected,
187199
dragging: isDragging,

editor-v2/hooks/useSelectedBlockBorders.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const useSelectedBlockBorders = (
2323

2424
// Update blockBorders when selectedBlock changes
2525
React.useEffect(() => {
26-
console.log(321, selectedBlock);
2726
if (!selectedBlock) {
2827
setBlockBorders(null);
2928
} else {
@@ -47,8 +46,5 @@ export const useSelectedBlockBorders = (
4746
}
4847
}, [blockBorders, canvasElement]);
4948

50-
React.useEffect(() => {
51-
console.log('blockBorders');
52-
}, [blockBorders]);
5349
return blockBorders;
5450
};

0 commit comments

Comments
 (0)