From 69db8a63d65088bc71ab225be0f841347758f61e Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 17 May 2024 20:23:13 +0000 Subject: [PATCH] fix: comment size not respecting collapsed-ness (#8136) * fix: comment size not respecting collapsed-ness * chore: fix tests the only way I know how, by adding explicit clock ticks --- core/comments/comment_view.ts | 7 +++++-- core/comments/rendered_workspace_comment.ts | 15 +++++++++++++-- tests/mocha/workspace_comment_test.js | 14 +++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/comments/comment_view.ts b/core/comments/comment_view.ts index c135e86f4..fbb9b3218 100644 --- a/core/comments/comment_view.ts +++ b/core/comments/comment_view.ts @@ -286,9 +286,12 @@ export class CommentView implements IRenderedElement { return this.svgRoot; } - /** Returns the current size of the comment in workspace units. */ + /** + * Returns the current size of the comment in workspace units. + * Respects collapsing. + */ getSize(): Size { - return this.size; + return this.collapsed ? this.topBarBackground.getBBox() : this.size; } /** diff --git a/core/comments/rendered_workspace_comment.ts b/core/comments/rendered_workspace_comment.ts index a70d5621e..8da0e8a72 100644 --- a/core/comments/rendered_workspace_comment.ts +++ b/core/comments/rendered_workspace_comment.ts @@ -120,10 +120,21 @@ export class RenderedWorkspaceComment return this.view.getSvgRoot(); } - /** Returns the bounding rectangle of this comment in workspace coordinates. */ + /** + * Returns the comment's size in workspace units. + * Does not respect collapsing. + */ + getSize(): Size { + return super.getSize(); + } + + /** + * Returns the bounding rectangle of this comment in workspace coordinates. + * Respects collapsing. + */ getBoundingRectangle(): Rect { const loc = this.getRelativeToSurfaceXY(); - const size = this.getSize(); + const size = this.view.getSize(); let left; let right; if (this.workspace.RTL) { diff --git a/tests/mocha/workspace_comment_test.js b/tests/mocha/workspace_comment_test.js index 977d82aa2..aa42cfbe2 100644 --- a/tests/mocha/workspace_comment_test.js +++ b/tests/mocha/workspace_comment_test.js @@ -15,7 +15,7 @@ import { suite('Workspace comment', function () { setup(function () { - sharedTestSetup.call(this); + this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock; this.workspace = new Blockly.inject('blocklyDiv', {}); }); @@ -31,6 +31,8 @@ suite('Workspace comment', function () { this.workspace, ); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentCreate, @@ -47,6 +49,8 @@ suite('Workspace comment', function () { this.renderedComment.dispose(); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentDelete, @@ -63,6 +67,8 @@ suite('Workspace comment', function () { this.renderedComment.moveTo(new Blockly.utils.Coordinate(42, 42)); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentMove, @@ -83,6 +89,8 @@ suite('Workspace comment', function () { this.renderedComment.setText('test text'); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentChange, @@ -103,6 +111,8 @@ suite('Workspace comment', function () { this.renderedComment.setCollapsed(true); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentCollapse, @@ -123,6 +133,8 @@ suite('Workspace comment', function () { this.renderedComment.setCollapsed(false); + this.clock.runAll(); + assertEventFired( spy, Blockly.Events.CommentCollapse,