mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
fix: Increases the speed of deleting blocks (#6128)
* fix: remove forced layout (~5ms) * fix: remove other use of getBBox for block * fix: Use Math.round rather than toFixed(0)
This commit is contained in:
@@ -59,9 +59,8 @@ const disposeUiEffect = function(block) {
|
||||
const clone = svgGroup.cloneNode(true);
|
||||
clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')');
|
||||
workspace.getParentSvg().appendChild(clone);
|
||||
const bBox = clone.getBBox();
|
||||
const cloneRect =
|
||||
{'x': xy.x, 'y': xy.y, 'width': bBox.width, 'height': bBox.height};
|
||||
{'x': xy.x, 'y': xy.y, 'width': block.width, 'height': block.height};
|
||||
// Start the animation.
|
||||
disposeUiStep(clone, cloneRect, workspace.RTL, new Date, workspace.scale);
|
||||
};
|
||||
|
||||
@@ -137,17 +137,14 @@ const BlockDragSurfaceSvg = class {
|
||||
*/
|
||||
translateAndScaleGroup(x, y, scale) {
|
||||
this.scale_ = scale;
|
||||
// This is a work-around to prevent a the blocks from rendering
|
||||
// fuzzy while they are being dragged on the drag surface.
|
||||
const fixedX = x.toFixed(0);
|
||||
const fixedY = y.toFixed(0);
|
||||
|
||||
this.childSurfaceXY_.x = parseInt(fixedX, 10);
|
||||
this.childSurfaceXY_.y = parseInt(fixedY, 10);
|
||||
|
||||
// Make sure the svg exists on a pixel boundary so that it is not fuzzy.
|
||||
const roundX = Math.round(x);
|
||||
const roundY = Math.round(y);
|
||||
this.childSurfaceXY_.x = roundX;
|
||||
this.childSurfaceXY_.y = roundY;
|
||||
this.dragGroup_.setAttribute(
|
||||
'transform',
|
||||
'translate(' + fixedX + ',' + fixedY + ') scale(' + scale + ')');
|
||||
'translate(' + roundX + ',' + roundY + ') scale(' + scale + ')');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,10 +154,9 @@ const BlockDragSurfaceSvg = class {
|
||||
translateSurfaceInternal_() {
|
||||
let x = this.surfaceXY_.x;
|
||||
let y = this.surfaceXY_.y;
|
||||
// This is a work-around to prevent a the blocks from rendering
|
||||
// fuzzy while they are being dragged on the drag surface.
|
||||
x = x.toFixed(0);
|
||||
y = y.toFixed(0);
|
||||
// Make sure the svg exists on a pixel boundary so that it is not fuzzy.
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
this.SVG_.style.display = 'block';
|
||||
|
||||
dom.setCssTransform(this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)');
|
||||
|
||||
@@ -293,10 +293,9 @@ exports.showPositionedByField = showPositionedByField;
|
||||
*/
|
||||
const getScaledBboxOfBlock = function(block) {
|
||||
const blockSvg = block.getSvgRoot();
|
||||
const bBox = blockSvg.getBBox();
|
||||
const scale = block.workspace.scale;
|
||||
const scaledHeight = bBox.height * scale;
|
||||
const scaledWidth = bBox.width * scale;
|
||||
const scaledHeight = block.height * scale;
|
||||
const scaledWidth = block.width * scale;
|
||||
const xy = style.getPageOffset(blockSvg);
|
||||
return new Rect(xy.y, xy.y + scaledHeight, xy.x, xy.x + scaledWidth);
|
||||
};
|
||||
|
||||
@@ -101,11 +101,9 @@ class WorkspaceDragSurfaceSvg {
|
||||
* @package
|
||||
*/
|
||||
translateSurface(x, y) {
|
||||
// This is a work-around to prevent a the blocks from rendering
|
||||
// fuzzy while they are being moved on the drag surface.
|
||||
const fixedX = x.toFixed(0);
|
||||
const fixedY = y.toFixed(0);
|
||||
|
||||
// Make sure the svg exists on a pixel boundary so that it is not fuzzy.
|
||||
const fixedX = Math.round(x);
|
||||
const fixedY = Math.round(y);
|
||||
this.SVG_.style.display = 'block';
|
||||
dom.setCssTransform(
|
||||
this.SVG_, 'translate3d(' + fixedX + 'px, ' + fixedY + 'px, 0)');
|
||||
|
||||
Reference in New Issue
Block a user