mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Disable resizing the workspace during clearing and loading from xml, as an optimization
This commit is contained in:
parent
81499e4392
commit
e2e2a3e298
4 changed files with 53 additions and 5 deletions
|
@ -264,7 +264,8 @@ Blockly.BlockSvg.terminateDrag = function() {
|
|||
delete selected.draggedBubbles_;
|
||||
selected.setDragging_(false);
|
||||
selected.render();
|
||||
// Ensure that any stap and bump are part of this move's event group.
|
||||
selected.workspace.setResizesEnabled(true);
|
||||
// Ensure that any snap and bump are part of this move's event group.
|
||||
var group = Blockly.Events.getGroup();
|
||||
setTimeout(function() {
|
||||
Blockly.Events.setGroup(group);
|
||||
|
@ -276,8 +277,6 @@ Blockly.BlockSvg.terminateDrag = function() {
|
|||
selected.bumpNeighbours_();
|
||||
Blockly.Events.setGroup(false);
|
||||
}, Blockly.BUMP_DELAY);
|
||||
// Fire an event to allow scrollbars to resize.
|
||||
selected.workspace.resizeContents();
|
||||
}
|
||||
}
|
||||
Blockly.dragMode_ = Blockly.DRAG_NONE;
|
||||
|
@ -870,6 +869,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
|
|||
// Switch to unrestricted dragging.
|
||||
Blockly.dragMode_ = Blockly.DRAG_FREE;
|
||||
Blockly.longStop_();
|
||||
this.workspace.setResizesEnabled(false);
|
||||
if (this.parentBlock_) {
|
||||
// Push this block to the very top of the stack.
|
||||
this.unplug();
|
||||
|
|
|
@ -1109,6 +1109,8 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) {
|
|||
block.onMouseDown_(e);
|
||||
Blockly.dragMode_ = Blockly.DRAG_FREE;
|
||||
block.setDragging_(true);
|
||||
// Disable workspace resizing. Reenable at the end of the drag.
|
||||
flyout.targetWorkspace_.setResizesEnabled(false);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -103,6 +103,14 @@ Blockly.WorkspaceSvg.prototype.isMutator = false;
|
|||
*/
|
||||
Blockly.WorkspaceSvg.prototype.dragMode_ = Blockly.DRAG_NONE;
|
||||
|
||||
/**
|
||||
* Whether this workspace has resizes enabled.
|
||||
* Disable during batch operations for a performance improvement.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.resizesEnabled_ = true;
|
||||
|
||||
/**
|
||||
* Current horizontal scrolling offset.
|
||||
* @type {number}
|
||||
|
@ -260,7 +268,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
|
|||
// Determine if there needs to be a category tree, or a simple list of
|
||||
// blocks. This cannot be changed later, since the UI is very different.
|
||||
if (this.options.hasCategories) {
|
||||
/**
|
||||
/**
|
||||
* @type {Blockly.Toolbox}
|
||||
* @private
|
||||
*/
|
||||
|
@ -389,12 +397,15 @@ Blockly.WorkspaceSvg.prototype.updateScreenCalculations_ = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Resize the parts of the workspace that change when the workspace
|
||||
* If enabled, resize the parts of the workspace that change when the workspace
|
||||
* contents (e.g. block positions) change. This will also scroll the
|
||||
* workspace contents if needed.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.resizeContents = function() {
|
||||
if (!this.resizesEnabled_) {
|
||||
return;
|
||||
}
|
||||
if (this.scrollbar) {
|
||||
// TODO(picklesrus): Once rachel-fenichel's scrollbar refactoring
|
||||
// is complete, call the method that only resizes scrollbar
|
||||
|
@ -1423,6 +1434,32 @@ Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update whether this workspace has resizes enabled.
|
||||
* If enabled, workspace will resize when appropriate.
|
||||
* If disabled, workspace will not resize until re-enabled.
|
||||
* Use to avoid resizing during a batch operation, for performance.
|
||||
* @param {boolean} enabled Whether resizes should be enabled.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.setResizesEnabled = function(enabled) {
|
||||
var reenabled = (!this.resizesEnabled_ && enabled);
|
||||
this.resizesEnabled_ = enabled;
|
||||
if (reenabled) {
|
||||
// Newly enabled. Trigger a resize.
|
||||
this.resizeContents();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of all blocks in workspace, with an optimization to prevent resizes.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.clear = function() {
|
||||
this.setResizesEnabled(false);
|
||||
Blockly.WorkspaceSvg.superClass_.clear.call(this);
|
||||
this.setResizesEnabled(true);
|
||||
};
|
||||
|
||||
// Export symbols that would otherwise be renamed by Closure compiler.
|
||||
Blockly.WorkspaceSvg.prototype['setVisible'] =
|
||||
Blockly.WorkspaceSvg.prototype.setVisible;
|
||||
|
|
|
@ -296,6 +296,11 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
if (!existingGroup) {
|
||||
Blockly.Events.setGroup(true);
|
||||
}
|
||||
|
||||
// Disable workspace resizes as an optimization.
|
||||
if (workspace.setResizesEnabled) {
|
||||
workspace.setResizesEnabled(false);
|
||||
}
|
||||
for (var i = 0; i < childCount; i++) {
|
||||
var xmlChild = xml.childNodes[i];
|
||||
var name = xmlChild.nodeName.toLowerCase();
|
||||
|
@ -320,6 +325,10 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
Blockly.Field.stopCache();
|
||||
|
||||
workspace.updateVariableList(false);
|
||||
// Re-enable workspace resizing.
|
||||
if (workspace.setResizesEnabled) {
|
||||
workspace.setResizesEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue