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
This commit is contained in:
Beka Westberg
2024-05-17 20:23:13 +00:00
committed by GitHub
parent 3fd749205f
commit 69db8a63d6
3 changed files with 31 additions and 5 deletions

View File

@@ -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;
}
/**

View File

@@ -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) {

View File

@@ -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,