From 435b0b92ee5aaad17c4d81b39c2e44fd97452cd0 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 13 Mar 2023 09:27:21 -0700 Subject: [PATCH] chore: cleanup render management (#6883) --- core/insertion_marker_manager.ts | 10 +++++++--- core/render_management.ts | 4 ++-- core/rendered_connection.ts | 14 ++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/insertion_marker_manager.ts b/core/insertion_marker_manager.ts index 20e27d426..8bb130964 100644 --- a/core/insertion_marker_manager.ts +++ b/core/insertion_marker_manager.ts @@ -194,9 +194,13 @@ export class InsertionMarkerManager { blockAnimations.connectionUiEffect(inferiorConnection.getSourceBlock()); // Bring the just-edited stack to the front. const rootBlock = this.topBlock.getRootBlock(); - setTimeout(() => { - rootBlock.bringToFront(); - }, 0); + + // bringToFront is incredibly expensive. Delay by at least a frame. + requestAnimationFrame(() => { + setTimeout(() => { + rootBlock.bringToFront(); + }, 0); + }); } } diff --git a/core/render_management.ts b/core/render_management.ts index a6a79f118..658f0b1d8 100644 --- a/core/render_management.ts +++ b/core/render_management.ts @@ -66,8 +66,8 @@ function doRenders() { } /** - * Recursively renders all of the children of the given block, and then renders - * the block. + * Recursively renders all of the dirty children of the given block, and + * then renders the block. * * @param block The block to rerender. */ diff --git a/core/rendered_connection.ts b/core/rendered_connection.ts index dbe729dd3..42cd94680 100644 --- a/core/rendered_connection.ts +++ b/core/rendered_connection.ts @@ -187,27 +187,25 @@ export class RenderedConnection extends Connection { * was updated. */ moveTo(x: number, y: number): boolean { - const dx = this.x - x; - const dy = this.y - y; - - let moved = false; + const moved = this.x !== x || this.y !== y; + let updated = false; if (this.trackedState_ === RenderedConnection.TrackedState.WILL_TRACK) { this.db_.addConnection(this, y); this.trackedState_ = RenderedConnection.TrackedState.TRACKED; - moved = true; + updated = true; } else if ( this.trackedState_ === RenderedConnection.TrackedState.TRACKED && - (dx !== 0 || dy !== 0)) { + moved) { this.db_.removeConnection(this, this.y); this.db_.addConnection(this, y); - moved = true; + updated = true; } this.x = x; this.y = y; - return moved; + return updated; } /**