88
99import type { Block } from '../block.js' ;
1010import type { BlockSvg } from '../block_svg.js' ;
11- import { TextBubble } from '../bubbles/text_bubble.js' ;
1211import { TextInputBubble } from '../bubbles/textinput_bubble.js' ;
1312import { EventType } from '../events/type.js' ;
1413import * as eventUtils from '../events/utils.js' ;
@@ -47,12 +46,9 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
4746 */
4847 static readonly WEIGHT = 3 ;
4948
50- /** The bubble used to show editable text to the user. */
49+ /** The bubble used to show comment text to the user. */
5150 private textInputBubble : TextInputBubble | null = null ;
5251
53- /** The bubble used to show non-editable text to the user. */
54- private textBubble : TextBubble | null = null ;
55-
5652 /** The text of this comment. */
5753 private text = '' ;
5854
@@ -118,7 +114,6 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
118114 override dispose ( ) {
119115 super . dispose ( ) ;
120116 this . textInputBubble ?. dispose ( ) ;
121- this . textBubble ?. dispose ( ) ;
122117 }
123118
124119 override getWeight ( ) : number {
@@ -133,7 +128,6 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
133128 super . applyColour ( ) ;
134129 const colour = ( this . sourceBlock as BlockSvg ) . style . colourPrimary ;
135130 this . textInputBubble ?. setColour ( colour ) ;
136- this . textBubble ?. setColour ( colour ) ;
137131 }
138132
139133 /**
@@ -153,7 +147,6 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
153147 super . onLocationChange ( blockOrigin ) ;
154148 const anchorLocation = this . getAnchorLocation ( ) ;
155149 this . textInputBubble ?. setAnchorLocation ( anchorLocation ) ;
156- this . textBubble ?. setAnchorLocation ( anchorLocation ) ;
157150 }
158151
159152 /** Sets the text of this comment. Updates any bubbles if they are visible. */
@@ -170,7 +163,6 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
170163 ) ;
171164 this . text = text ;
172165 this . textInputBubble ?. setText ( this . text ) ;
173- this . textBubble ?. setText ( this . text ) ;
174166 }
175167
176168 /** Returns the text of this comment. */
@@ -302,33 +294,31 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable {
302294 * to update the state of this icon in response to changes in the bubble.
303295 */
304296 private showEditableBubble ( ) {
305- this . textInputBubble = new TextInputBubble (
306- this . sourceBlock . workspace as WorkspaceSvg ,
307- this . getAnchorLocation ( ) ,
308- this . getBubbleOwnerRect ( ) ,
309- ) ;
310- this . textInputBubble . setText ( this . getText ( ) ) ;
311- this . textInputBubble . setSize ( this . bubbleSize , true ) ;
312- this . textInputBubble . addTextChangeListener ( ( ) => this . onTextChange ( ) ) ;
313- this . textInputBubble . addSizeChangeListener ( ( ) => this . onSizeChange ( ) ) ;
297+ this . createBubble ( ) ;
298+ this . textInputBubble ?. addTextChangeListener ( ( ) => this . onTextChange ( ) ) ;
299+ this . textInputBubble ?. addSizeChangeListener ( ( ) => this . onSizeChange ( ) ) ;
314300 }
315301
316302 /** Shows the non editable text bubble for this comment. */
317303 private showNonEditableBubble ( ) {
318- this . textBubble = new TextBubble (
319- this . getText ( ) ,
304+ this . createBubble ( ) ;
305+ this . textInputBubble ?. setEditable ( false ) ;
306+ }
307+
308+ protected createBubble ( ) {
309+ this . textInputBubble = new TextInputBubble (
320310 this . sourceBlock . workspace as WorkspaceSvg ,
321311 this . getAnchorLocation ( ) ,
322312 this . getBubbleOwnerRect ( ) ,
323313 ) ;
314+ this . textInputBubble . setText ( this . getText ( ) ) ;
315+ this . textInputBubble . setSize ( this . bubbleSize , true ) ;
324316 }
325317
326318 /** Hides any open bubbles owned by this comment. */
327319 private hideBubble ( ) {
328320 this . textInputBubble ?. dispose ( ) ;
329321 this . textInputBubble = null ;
330- this . textBubble ?. dispose ( ) ;
331- this . textBubble = null ;
332322 }
333323
334324 /**
0 commit comments