MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / setCommentText

Method setCommentText

packages/blockly/core/block.ts:2345–2387  ·  view source on GitHub ↗

* Set this block's comment text. * * @param text The text, or null to delete.

(text: string | null)

Source from the content-addressed store, hash-verified

2343 * @param text The text, or null to delete.
2344 */
2345 setCommentText(text: string | null) {
2346 const comment = this.getIcon(IconType.COMMENT);
2347 const oldText = comment?.getText() ?? null;
2348 if (oldText === text) return;
2349 if (text !== null) {
2350 let comment = this.getIcon(IconType.COMMENT);
2351 if (!comment) {
2352 const commentConstructor = registry.getClass(
2353 registry.Type.ICON,
2354 IconType.COMMENT.toString(),
2355 false,
2356 );
2357 if (!commentConstructor) {
2358 throw new Error(
2359 'No comment icon class is registered, so a comment cannot be set',
2360 );
2361 }
2362 const icon = new commentConstructor(this);
2363 if (!isCommentIcon(icon)) {
2364 throw new Error(
2365 'The class registered as a comment icon does not conform to the ' +
2366 'ICommentIcon interface',
2367 );
2368 }
2369 comment = this.addIcon(icon);
2370 }
2371 eventUtils.disable();
2372 comment.setText(text);
2373 eventUtils.enable();
2374 } else {
2375 this.removeIcon(IconType.COMMENT);
2376 }
2377
2378 eventUtils.fire(
2379 new (eventUtils.get(EventType.BLOCK_CHANGE))(
2380 this,
2381 'comment',
2382 null,
2383 oldText,
2384 text,
2385 ),
2386 );
2387 }
2388
2389 /**
2390 * Set this block's warning text.

Callers 15

applyCommentTagNodesFunction · 0.80
callbackFunction · 0.80
runMethod · 0.80
procedures.tsFile · 0.80
block_test.jsFile · 0.80
comment_test.jsFile · 0.80
event_test.jsFile · 0.80
xml_test.jsFile · 0.80

Calls 8

getIconMethod · 0.95
addIconMethod · 0.95
removeIconMethod · 0.95
isCommentIconFunction · 0.85
getMethod · 0.80
getTextMethod · 0.65
setTextMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected