• LongCatIsLooong's avatar
    Reland "Make `TextSpan` hit testing precise." (#140468) (#140621) · 5883a6ca
    LongCatIsLooong authored
    Fixes https://github.com/flutter/flutter/issues/131435, https://github.com/flutter/flutter/issues/104594, https://github.com/flutter/flutter/issues/43400
    
    Currently the method we use for text span hit testing `TextPainter.getPositionForOffset` always returns the closest `TextPosition`, even when the given offset is far away from the text.
    
    The new TextPaintes method tells you the layout bounds `(width =  letterspacing / 2 + x_advance + letterspacing / 2, height = font ascent + font descent)` of a character, the PR changes the hit testing implementation such that a TextSpan is only considered hit if the point-down event landed in one of its character's layout bounds.
    
    Potential issues:
    
    In theory since the text is baseline aligned, we should use the max ascent and max descent of each character to calculate the height of the text span's hit-test region, in case some characters in the span have to fall back to a different font, but that will be slower and it typically doesn't make a huge difference.
    This is a breaking change.
    5883a6ca
Name
Last commit
Last update
..
_network_image_io.dart Loading commit data...
_network_image_web.dart Loading commit data...
alignment.dart Loading commit data...
basic_types.dart Loading commit data...
beveled_rectangle_border.dart Loading commit data...
binding.dart Loading commit data...
border_radius.dart Loading commit data...
borders.dart Loading commit data...
box_border.dart Loading commit data...
box_decoration.dart Loading commit data...
box_fit.dart Loading commit data...
box_shadow.dart Loading commit data...
circle_border.dart Loading commit data...
clip.dart Loading commit data...
colors.dart Loading commit data...
continuous_rectangle_border.dart Loading commit data...
debug.dart Loading commit data...
decoration.dart Loading commit data...
decoration_image.dart Loading commit data...
edge_insets.dart Loading commit data...
flutter_logo.dart Loading commit data...
fractional_offset.dart Loading commit data...
geometry.dart Loading commit data...
gradient.dart Loading commit data...
image_cache.dart Loading commit data...
image_decoder.dart Loading commit data...
image_provider.dart Loading commit data...
image_resolution.dart Loading commit data...
image_stream.dart Loading commit data...
inline_span.dart Loading commit data...
linear_border.dart Loading commit data...
matrix_utils.dart Loading commit data...
notched_shapes.dart Loading commit data...
oval_border.dart Loading commit data...
paint_utilities.dart Loading commit data...
placeholder_span.dart Loading commit data...
rounded_rectangle_border.dart Loading commit data...
shader_warm_up.dart Loading commit data...
shape_decoration.dart Loading commit data...
stadium_border.dart Loading commit data...
star_border.dart Loading commit data...
strut_style.dart Loading commit data...
text_painter.dart Loading commit data...
text_scaler.dart Loading commit data...
text_span.dart Loading commit data...
text_style.dart Loading commit data...