Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ export abstract class Flyout
*/
private reflowWrapper: ((e: AbstractEvent) => void) | null = null;

/**
* If true, prevents the reflow wrapper from running. Used to prevent infinite
* recursion.
*/
private inhibitReflowWrapper = false;

/**
* List of flyout elements.
*/
Expand Down Expand Up @@ -647,6 +653,7 @@ export abstract class Flyout
// accommodates e.g. resizing a non-autoclosing flyout in response to the
// user typing long strings into fields on the blocks in the flyout.
this.reflowWrapper = (event) => {
if (this.inhibitReflowWrapper) return;
if (
event.type === EventType.BLOCK_CHANGE ||
event.type === EventType.BLOCK_FIELD_INTERMEDIATE_CHANGE
Expand Down Expand Up @@ -844,13 +851,9 @@ export abstract class Flyout
* Reflow flyout contents.
*/
reflow() {
if (this.reflowWrapper) {
this.workspace_.removeChangeListener(this.reflowWrapper);
}
this.inhibitReflowWrapper = true;
this.reflowInternal_();
if (this.reflowWrapper) {
this.workspace_.addChangeListener(this.reflowWrapper);
}
this.inhibitReflowWrapper = false;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/mocha/flyout_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ suite('Flyout', function () {
sharedTestTeardown.call(this);
});

suite('workspace change listeners', function () {
test('are triggered when a child block changes', function () {
let listenerTriggered = false;
const listener = (e) => {
if (e.type === Blockly.Events.BLOCK_CHANGE) {
listenerTriggered = true;
}
};
this.workspace.getFlyout().getWorkspace().addChangeListener(listener);
const boolBlock = this.workspace
.getFlyout()
.getWorkspace()
.getBlocksByType('logic_compare')[0];
boolBlock.getField('OP').setValue('LTE');
this.clock.tick(1000);
assert.isTrue(listenerTriggered);
this.workspace.getFlyout().getWorkspace().removeChangeListener(listener);
});
});

suite('position', function () {
suite('vertical flyout', function () {
suite('simple flyout', function () {
Expand Down
Loading