Skip to content

Commit

Permalink
In SceneGraph, only scroll node into view if it's not currently visib…
Browse files Browse the repository at this point in the history
…le and now that we don't scroll when we double click on a scene graph node, decrease the timeout from 500ms to 100ms just so React create the node we're interested in. (#784)
  • Loading branch information
vincentfretin authored Jan 6, 2025
1 parent 0a8c2b6 commit e23d845
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/scenegraph/SceneGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ export default class SceneGraph extends React.Component {
if (entityOption.entity === entity) {
this.setState({ selectedIndex: i });
setTimeout(() => {
// wait 500ms to allow user to double click on entity
document
.getElementById('sgnode' + i)
?.scrollIntoView({ behavior: 'smooth' });
}, 500);
// wait 100ms to allow React to update the UI and create the node we're interested in
const node = document.getElementById('sgnode' + i);
const scrollableContainer = document.querySelector(
'#scenegraph .outliner'
);
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' });
}
}, 100);
// Make sure selected value is visible in scenegraph
this.expandToRoot(entity);
Events.emit('entityselect', entity);
Expand Down

0 comments on commit e23d845

Please sign in to comment.