@@ -90,6 +90,7 @@ public TextSpan text {
90
90
return ;
91
91
case RenderComparison . function :
92
92
this . _textPainter . text = value ;
93
+ this . markNeedsPaint ( ) ;
93
94
break ;
94
95
case RenderComparison . paint :
95
96
this . _textPainter . text = value ;
@@ -251,11 +252,30 @@ public bool hasFocus {
251
252
TextSpan _previousHoverSpan ;
252
253
bool _pointerHoverInside ;
253
254
bool _hasHoverRecognizer ;
255
+ MouseTrackerAnnotation _hoverAnnotation ;
254
256
255
257
void _resetHoverHandler ( ) {
256
258
this . _hasHoverRecognizer = this . _textPainter . text . hasHoverRecognizer ;
257
259
this . _previousHoverSpan = null ;
258
260
this . _pointerHoverInside = false ;
261
+
262
+ if ( this . _hoverAnnotation != null && this . attached ) {
263
+ RendererBinding . instance . mouseTracker . detachAnnotation ( this . _hoverAnnotation ) ;
264
+ }
265
+
266
+ if ( this . _hasHoverRecognizer ) {
267
+ this . _hoverAnnotation = new MouseTrackerAnnotation (
268
+ onEnter : this . _onPointerEnter ,
269
+ onHover : this . _onPointerHover ,
270
+ onExit : this . _onPointerExit ) ;
271
+
272
+ if ( this . attached ) {
273
+ RendererBinding . instance . mouseTracker . attachAnnotation ( this . _hoverAnnotation ) ;
274
+ }
275
+ }
276
+ else {
277
+ this . _hoverAnnotation = null ;
278
+ }
259
279
}
260
280
261
281
void _handleKeyEvent ( RawKeyEvent keyEvent ) {
@@ -288,12 +308,22 @@ void _handleKeyEvent(RawKeyEvent keyEvent) {
288
308
}
289
309
}
290
310
311
+ public override void attach ( object owner ) {
312
+ base . attach ( owner ) ;
313
+ if ( this . _hoverAnnotation != null ) {
314
+ RendererBinding . instance . mouseTracker . attachAnnotation ( this . _hoverAnnotation ) ;
315
+ }
316
+ }
317
+
291
318
public override void detach ( ) {
292
319
if ( this . _listenerAttached ) {
293
320
RawKeyboard . instance . removeListener ( this . _handleKeyEvent ) ;
294
321
}
295
322
296
323
base . detach ( ) ;
324
+ if ( this . _hoverAnnotation != null ) {
325
+ RendererBinding . instance . mouseTracker . detachAnnotation ( this . _hoverAnnotation ) ;
326
+ }
297
327
}
298
328
299
329
TextSelection _selection ;
@@ -333,46 +363,40 @@ void _handleSelectionChanged(TextSelection selection,
333
363
this . onSelectionChanged ? . Invoke ( ) ;
334
364
}
335
365
366
+ void _onPointerEnter ( PointerEvent evt ) {
367
+ this . _pointerHoverInside = true ;
368
+ }
336
369
337
- void _handlePointerHover ( PointerEvent evt ) {
338
- if ( ! this . _hasHoverRecognizer ) {
339
- return ;
340
- }
370
+ void _onPointerExit ( PointerEvent evt ) {
371
+ this . _pointerHoverInside = false ;
372
+ this . _previousHoverSpan ? . hoverRecognizer ? . OnPointerLeave ? . Invoke ( ) ;
373
+ this . _previousHoverSpan = null ;
374
+ }
341
375
342
- if ( evt is PointerEnterEvent ) {
343
- this . _pointerHoverInside = true ;
344
- }
345
- else if ( evt is PointerExitEvent ) {
346
- this . _pointerHoverInside = false ;
376
+ void _onPointerHover ( PointerEvent evt ) {
377
+ this . _layoutTextWithConstraints ( this . constraints ) ;
378
+ Offset offset = this . globalToLocal ( evt . position ) ;
379
+ TextPosition position = this . _textPainter . getPositionForOffset ( offset ) ;
380
+ TextSpan span = this . _textPainter . text . getSpanForPosition ( position ) ;
381
+
382
+ if ( this . _previousHoverSpan != span ) {
347
383
this . _previousHoverSpan ? . hoverRecognizer ? . OnPointerLeave ? . Invoke ( ) ;
348
- this . _previousHoverSpan = null ;
349
- }
350
- else if ( evt is PointerHoverEvent && this . _pointerHoverInside ) {
351
- this . _layoutTextWithConstraints ( this . constraints ) ;
352
- Offset offset = this . globalToLocal ( evt . position ) ;
353
- TextPosition position = this . _textPainter . getPositionForOffset ( offset ) ;
354
- TextSpan span = this . _textPainter . text . getSpanForPosition ( position ) ;
355
-
356
- if ( this . _previousHoverSpan != span ) {
357
- this . _previousHoverSpan ? . hoverRecognizer ? . OnPointerLeave ? . Invoke ( ) ;
358
- span ? . hoverRecognizer ? . OnPointerEnter ? . Invoke ( ( PointerHoverEvent ) evt ) ;
359
- this . _previousHoverSpan = span ;
360
- }
384
+ span ? . hoverRecognizer ? . OnPointerEnter ? . Invoke ( ( PointerHoverEvent ) evt ) ;
385
+ this . _previousHoverSpan = span ;
361
386
}
362
387
}
363
388
364
389
public override void handleEvent ( PointerEvent evt , HitTestEntry entry ) {
365
390
D . assert ( this . debugHandleEvent ( evt , entry ) ) ;
366
- if ( evt is PointerDownEvent ) {
367
- this . _layoutTextWithConstraints ( this . constraints ) ;
368
- Offset offset = ( ( BoxHitTestEntry ) entry ) . localPosition ;
369
- TextPosition position = this . _textPainter . getPositionForOffset ( offset ) ;
370
- TextSpan span = this . _textPainter . text . getSpanForPosition ( position ) ;
371
- span ? . recognizer ? . addPointer ( ( PointerDownEvent ) evt ) ;
391
+ if ( ! ( evt is PointerDownEvent ) ) {
372
392
return ;
373
393
}
374
-
375
- this . _handlePointerHover ( evt ) ;
394
+
395
+ this . _layoutTextWithConstraints ( this . constraints ) ;
396
+ Offset offset = ( ( BoxHitTestEntry ) entry ) . localPosition ;
397
+ TextPosition position = this . _textPainter . getPositionForOffset ( offset ) ;
398
+ TextSpan span = this . _textPainter . text . getSpanForPosition ( position ) ;
399
+ span ? . recognizer ? . addPointer ( ( PointerDownEvent ) evt ) ;
376
400
}
377
401
378
402
protected override void performLayout ( ) {
@@ -387,7 +411,8 @@ protected override void performLayout() {
387
411
this . _selectionRects = null ;
388
412
}
389
413
390
- public override void paint ( PaintingContext context , Offset offset ) {
414
+
415
+ void paintParagraph ( PaintingContext context , Offset offset ) {
391
416
this . _layoutTextWithConstraints ( this . constraints ) ;
392
417
var canvas = context . canvas ;
393
418
@@ -411,6 +436,18 @@ public override void paint(PaintingContext context, Offset offset) {
411
436
}
412
437
}
413
438
439
+ public override void paint ( PaintingContext context , Offset offset ) {
440
+ if ( this . _hoverAnnotation != null ) {
441
+ AnnotatedRegionLayer < MouseTrackerAnnotation > layer = new AnnotatedRegionLayer < MouseTrackerAnnotation > (
442
+ this . _hoverAnnotation , size : this . size , offset : offset ) ;
443
+
444
+ context . pushLayer ( layer , this . paintParagraph , offset ) ;
445
+ }
446
+ else {
447
+ this . paintParagraph ( context , offset ) ;
448
+ }
449
+ }
450
+
414
451
415
452
void _paintSelection ( Canvas canvas , Offset effectiveOffset ) {
416
453
D . assert ( this . _selectionRects != null ) ;
0 commit comments