Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion core/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
Blockly.mainWorkspace = mainWorkspace;

if (!options.readOnly && !options.hasScrollbars) {
var workspaceChanged = function() {
var workspaceChanged = function(e) {
if (!mainWorkspace.isDragging()) {
var metrics = mainWorkspace.getMetrics();
var edgeLeft = metrics.viewLeft + metrics.absoluteLeft;
Expand All @@ -239,32 +239,49 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
// One or more blocks may be out of bounds. Bump them back in.
var MARGIN = 25;
var blocks = mainWorkspace.getTopBlocks(false);
var oldGroup = null;
if (e) {
oldGroup = Blockly.Events.getGroup();
Blockly.Events.setGroup(e.group);
}
var movedBlocks = false;
for (var b = 0, block; block = blocks[b]; b++) {
var blockXY = block.getRelativeToSurfaceXY();
var blockHW = block.getHeightWidth();
// Bump any block that's above the top back inside.
var overflowTop = edgeTop + MARGIN - blockHW.height - blockXY.y;
if (overflowTop > 0) {
block.moveBy(0, overflowTop);
movedBlocks = true;
}
// Bump any block that's below the bottom back inside.
var overflowBottom =
edgeTop + metrics.viewHeight - MARGIN - blockXY.y;
if (overflowBottom < 0) {
block.moveBy(0, overflowBottom);
movedBlocks = true;
}
// Bump any block that's off the left back inside.
var overflowLeft = MARGIN + edgeLeft -
blockXY.x - (options.RTL ? 0 : blockHW.width);
if (overflowLeft > 0) {
block.moveBy(overflowLeft, 0);
movedBlocks = true;
}
// Bump any block that's off the right back inside.
var overflowRight = edgeLeft + metrics.viewWidth - MARGIN -
blockXY.x + (options.RTL ? blockHW.width : 0);
if (overflowRight < 0) {
block.moveBy(overflowRight, 0);
movedBlocks = true;
}
}
if (e) {
if (!e.group && movedBlocks) {
console.log('WARNING: Moved blocks in bounds but there was no event group.'
+ ' This may break undo.');
}
Blockly.Events.setGroup(oldGroup);
}
}
}
Expand Down