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 0a35582
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 sgNode = document.getElementById('sgnode' + i);
const scrollableContainer = document.querySelector(
'#scenegraph .layers'
);
if (!sgNode || !scrollableContainer) return;
const parentRect = scrollableContainer.getBoundingClientRect();
const elementRect = sgNode.getBoundingClientRect();
const isVisible =
elementRect.top >= parentRect.top &&
elementRect.bottom <= parentRect.bottom;
if (!isVisible) {
sgNode.scrollIntoView({ behavior: 'smooth' });
}
}, 500);
// Make sure selected value is visible in scenegraph
this.expandToRoot(entity);
Expand Down

0 comments on commit 0a35582

Please sign in to comment.