mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
fix: collapsing blocks with children with icons (#7111)
* fix: collapsing blocks with icons * chore: add tests for hiding icons of collapsed children
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
export interface IHasBubble {
|
||||
/** @return True if the bubble is currently open, false otherwise. */
|
||||
isBubbleVisible(): boolean;
|
||||
bubbleIsVisible(): boolean;
|
||||
|
||||
/** Sets whether the bubble is open or not. */
|
||||
setBubbleVisible(visible: boolean): void;
|
||||
@@ -15,6 +15,6 @@ export interface IHasBubble {
|
||||
/** Type guard that checks whether the given object is a IHasBubble. */
|
||||
export function hasBubble(obj: any): obj is IHasBubble {
|
||||
return (
|
||||
obj.isBubbleVisible !== undefined && obj.setBubbleVisible !== undefined
|
||||
obj.bubbleIsVisible !== undefined && obj.setBubbleVisible !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import {Connection} from './connection.js';
|
||||
import type {ConnectionDB} from './connection_db.js';
|
||||
import {ConnectionType} from './connection_type.js';
|
||||
import * as eventUtils from './events/utils.js';
|
||||
import {hasBubble} from './interfaces/i_has_bubble.js';
|
||||
import * as internalConstants from './internal_constants.js';
|
||||
import {Coordinate} from './utils/coordinate.js';
|
||||
import * as dom from './utils/dom.js';
|
||||
@@ -428,9 +429,13 @@ export class RenderedConnection extends Connection {
|
||||
connections[j].setTracking(false);
|
||||
}
|
||||
// Close all bubbles of all children.
|
||||
const icons = block.getIcons();
|
||||
for (let j = 0; j < icons.length; j++) {
|
||||
icons[j].setVisible(false);
|
||||
for (const icon of block.getIcons()) {
|
||||
if (hasBubble(icon)) {
|
||||
icon.setBubbleVisible(false);
|
||||
} else if (icon.setVisible) {
|
||||
// TODO (#7042): Remove old icon handling code.
|
||||
icon.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ export class Icon extends Measurable {
|
||||
// TODO(#7042): Remove references to old icon API.
|
||||
this.isVisible =
|
||||
(icon.isVisible && icon.isVisible()) ||
|
||||
(hasBubble(icon) && icon.isBubbleVisible());
|
||||
(hasBubble(icon) && icon.bubbleIsVisible());
|
||||
this.type |= Types.ICON;
|
||||
|
||||
const size =
|
||||
|
||||
Reference in New Issue
Block a user