* Set this block's comment text. * * @param text The text, or null to delete.
(text: string | null)
| 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. |
no test coverage detected