Skip to content

Commit

Permalink
In SceneGraph, only scroll node into view if it's not currently visible
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentfretin committed Dec 21, 2024
1 parent 2926a00 commit c2cbbb6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/editor/components/scenegraph/SceneGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,19 @@ export default class SceneGraph extends React.Component {
this.setState({ selectedIndex: i });
setTimeout(() => {
// wait 500ms to allow user to double click on entity
document
.getElementById('sgnode' + i)
?.scrollIntoView({ behavior: 'smooth' });
const node = document.getElementById('sgnode' + i);
const scrollableContainer = document.querySelector(
'#scenegraph .layers'
);
if (!node || !scrollableContainer) return;
const containerRect = scrollableContainer.getBoundingClientRect();
const nodeRect = node.getBoundingClientRect();
const isVisible =
nodeRect.top >= containerRect.top &&
nodeRect.bottom <= containerRect.bottom;
if (!isVisible) {
node.scrollIntoView({ behavior: 'smooth' });
}
}, 500);
// Make sure selected value is visible in scenegraph
this.expandToRoot(entity);
Expand Down

0 comments on commit c2cbbb6

Please sign in to comment.