• LongCatIsLooong's avatar
    Make `TextSpan` hit testing precise. (#139717) · ea5b9728
    LongCatIsLooong authored
    Fixes https://github.com/flutter/flutter/issues/131435, #104594, #43400
    Needs https://github.com/flutter/engine/pull/48774 (to fix the web test failure).
    
    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 it's character's layout bounds.
    
    Potential issues:
    
    1. 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. It also introduces a new finder and a new method `WidgetTester.tapOnText`: `await tester.tapOnText('string to match')` for ease of migration.
    ea5b9728
Name
Last commit
Last update
..
bindings_environment Loading commit data...
custom_exception_reporter Loading commit data...
semantics_checker Loading commit data...
test_config Loading commit data...
utils Loading commit data...
accessibility_test.dart Loading commit data...
accessibility_window_test.dart Loading commit data...
all_elements_test.dart Loading commit data...
analysis_options.yaml Loading commit data...
bindings_async_gap_test.dart Loading commit data...
bindings_reset_test.dart Loading commit data...
bindings_restoration_test.dart Loading commit data...
bindings_test.dart Loading commit data...
bindings_test_failure.dart Loading commit data...
controller_test.dart Loading commit data...
coordinate_translation_test.dart Loading commit data...
demangle_test.dart Loading commit data...
display_test.dart Loading commit data...
event_simulation_test.dart Loading commit data...
finders_test.dart Loading commit data...
frame_timing_summarizer_test.dart Loading commit data...
goldens_test.dart Loading commit data...
integration_bindings_test.dart Loading commit data...
live_binding_test.dart Loading commit data...
live_widget_controller_test.dart Loading commit data...
matchers_test.dart Loading commit data...
mock_canvas_test.dart Loading commit data...
multi_view_accessibility_test.dart Loading commit data...
multi_view_controller_test.dart Loading commit data...
multi_view_testing.dart Loading commit data...
platform_dispatcher_test.dart Loading commit data...
reference_image_test.dart Loading commit data...
restoration_test.dart Loading commit data...
stack_manipulation_test.dart Loading commit data...
test_async_utils_test.dart Loading commit data...
test_default_binary_messenger_test.dart Loading commit data...
test_text_input_test.dart Loading commit data...
view_test.dart Loading commit data...
widget_tester_live_device_test.dart Loading commit data...
widget_tester_test.dart Loading commit data...
window_test.dart Loading commit data...