@@ -45,7 +45,8 @@ import TutorialMessage from '../../Hints/TutorialMessage';
4545import getTutorial from '../../Hints/getTutorial' ;
4646import { makeDragSourceAndDropTarget } from '../../UI/DragAndDrop/DragSourceAndDropTarget' ;
4747import { makeDropTarget } from '../../UI/DragAndDrop/DropTarget' ;
48- import { AutoScroll , DropContainer } from './DropContainer' ;
48+ import { DropContainer } from './DropContainer' ;
49+ import { useAutoScrollDuringAnyDrag } from '../../UI/DragAndDrop/UseAutoScrollDuringDrag' ;
4950import {
5051 isDescendant ,
5152 isElseEventValid ,
@@ -511,9 +512,13 @@ const EventsTree: React.ComponentType<{
511512 const _hoverTimerId = React . useRef < ?TimeoutID > ( null ) ;
512513
513514 const [ draggedNode , setDraggedNode ] = React . useState ( null ) ;
514- const [ isScrolledTop , setIsScrolledTop ] = React . useState ( true ) ;
515- const [ isScrolledBottom , setIsScrolledBottom ] = React . useState ( false ) ;
516515 const lastKnownScrollPosition = React . useRef ( 0 ) ;
516+ // Scroll when events, but also instructions or variable declarations,
517+ // are dragged close to the edges.
518+ useAutoScrollDuringAnyDrag (
519+ ( ) => ( _list . current ? _list . current . container : null ) ,
520+ { maxSpeed : 900 }
521+ ) ;
517522
518523 // This is the data that will be displayed by the tree - reconstructed at each render
519524 // (because events could have changed, some could have been deleted, so we can't keep
@@ -1227,14 +1232,6 @@ const EventsTree: React.ComponentType<{
12271232 [ ]
12281233 ) ;
12291234
1230- const _scrollUp = React . useCallback ( ( ) => {
1231- _list . current && _list . current . container . scrollBy ( { top : - 5 } ) ;
1232- } , [ ] ) ;
1233-
1234- const _scrollDown = React . useCallback ( ( ) => {
1235- _list . current && _list . current . container . scrollBy ( { top : 5 } ) ;
1236- } , [ ] ) ;
1237-
12381235 const zoomLevel = props . fontSize || 14 ;
12391236
12401237 // Update treeDataRoot with the events tree. Done at each render as events
@@ -1249,9 +1246,7 @@ const EventsTree: React.ComponentType<{
12491246 React . useLayoutEffect ( ( ) => {
12501247 // Recompute row heights on every render. This is needed for any change
12511248 // that affects which event is at which row (deletion, fold/unfold, move)
1252- // — not just changes to individual event heights. Scroll-triggered
1253- // re-renders (isScrolledTop / isScrolledBottom state flips) are infrequent
1254- // and recalculate the same heights, so the extra work is negligible.
1249+ // — not just changes to individual event heights.
12551250 if ( _list . current ) {
12561251 _list . current . recomputeRowHeights ( ) ;
12571252 }
@@ -1282,26 +1277,6 @@ const EventsTree: React.ComponentType<{
12821277 ) } px`,
12831278 } }
12841279 >
1285- { /* Disable for touchscreen because the dragged DOM node gets deleted, the */ }
1286- { /* touch events are lost and the dnd does not drop anymore (hypothesis). */ }
1287- { props . screenType !== 'touch' && (
1288- < >
1289- < AutoScroll
1290- DnDComponent = { EventDropTarget }
1291- direction = "top"
1292- // $FlowFixMe[constant-condition]
1293- activateTargets = { ! ! draggedNode && ! isScrolledTop }
1294- onHover = { _scrollUp }
1295- />
1296- < AutoScroll
1297- DnDComponent = { EventDropTarget }
1298- direction = "bottom"
1299- // $FlowFixMe[constant-condition]
1300- activateTargets = { ! ! draggedNode && ! isScrolledBottom }
1301- onHover = { _scrollDown }
1302- />
1303- </ >
1304- ) }
13051280 < SortableTree
13061281 treeData = {
13071282 // Pass a new array each time, otherwise the tree will not re-render.
@@ -1332,10 +1307,6 @@ const EventsTree: React.ComponentType<{
13321307 }
13331308 lastKnownScrollPosition . current = event . scrollTop ;
13341309 props . onScroll && props . onScroll ( ) ;
1335- setIsScrolledTop ( event . scrollTop === 0 ) ;
1336- setIsScrolledBottom (
1337- event . clientHeight + event . scrollTop >= event . scrollHeight
1338- ) ;
13391310 } ,
13401311 // 'smart': no-op if the row is already visible; centers it only when
13411312 // it is more than one viewport away. This prevents undo of an in-view
0 commit comments