Skip to content

Commit 4ff2247

Browse files
fix: avoid scrolling into view for mouse interactions. (#330)
Fixes #300
1 parent cb1e697 commit 4ff2247

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/workspace_utilities.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,15 @@ import * as Blockly from 'blockly/core';
1717
* @param workspace The workspace to scroll the given bounds into view in.
1818
*/
1919
export function scrollBoundsIntoView(
20-
originalBounds: Blockly.utils.Rect,
20+
bounds: Blockly.utils.Rect,
2121
workspace: Blockly.WorkspaceSvg,
2222
) {
23+
if (Blockly.Gesture.inProgress()) {
24+
// This can cause jumps during a drag and it only suited for keyboard nav.
25+
return;
26+
}
2327
const scale = workspace.getScale();
2428

25-
const bounds = originalBounds.clone();
26-
27-
// Add some padding to the bounds so the element is scrolled comfortably
28-
// into view.
29-
bounds.top -= 10;
30-
bounds.bottom += 10;
31-
bounds.left -= 10;
32-
bounds.right += 10;
33-
3429
const rawViewport = workspace.getMetricsManager().getViewMetrics(true);
3530
const viewport = new Blockly.utils.Rect(
3631
rawViewport.top,
@@ -49,6 +44,14 @@ export function scrollBoundsIntoView(
4944
return;
5045
}
5146

47+
// Add some padding to the bounds so the element is scrolled comfortably
48+
// into view.
49+
bounds = bounds.clone();
50+
bounds.top -= 10;
51+
bounds.bottom += 10;
52+
bounds.left -= 10;
53+
bounds.right += 10;
54+
5255
let deltaX = 0;
5356
let deltaY = 0;
5457

0 commit comments

Comments
 (0)