From 71e835672703237deb0d1adf2d551cc9b114f443 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 29 Apr 2022 09:12:38 -0700 Subject: [PATCH] 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) --- core/block_animations.js | 3 +-- core/block_drag_surface.js | 22 +++++++++------------- core/dropdowndiv.js | 5 ++--- core/workspace_drag_surface_svg.js | 8 +++----- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index f41c08527..47eb6404b 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -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); }; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index c0b01094a..4cdeea8e1 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -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)'); diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index bd6e8afea..163c79317 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -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); }; diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 51f9a901d..e298bf0f4 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -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)');