Skip to content

Commit

Permalink
fix: Increases the speed of deleting blocks (#6128)
Browse files Browse the repository at this point in the history
* fix: remove forced layout (~5ms)

* fix: remove other use of getBBox for block

* fix: Use Math.round rather than toFixed(0)
  • Loading branch information
BeksOmega committed Apr 29, 2022
1 parent b7cd2e1 commit 71e8356
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
3 changes: 1 addition & 2 deletions core/block_animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
22 changes: 9 additions & 13 deletions core/block_drag_surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ')');
}

/**
Expand All @@ -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)');
Expand Down
5 changes: 2 additions & 3 deletions core/dropdowndiv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
8 changes: 3 additions & 5 deletions core/workspace_drag_surface_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand Down

0 comments on commit 71e8356

Please sign in to comment.