Skip to content
Snippets Groups Projects
Unverified Commit f50c6c0f authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub
Browse files

[web] Fix multiline input selection in Chrome. (#168217)

Fixes https://github.com/flutter/flutter/issues/167805
Fixes https://github.com/flutter/flutter/issues/162698

### Description

First of all, I would like to thank @jezell for posting their fix of
this selection issue:
https://github.com/singerdmx/flutter-quill/issues/2450#issuecomment-2754652065

The issue with selection is happening because in Chrome `pointermove`
event and its coalesced events have some different targets. @mdebbar
already spotted this behavior some time ago and even filed a Chrome bug:
https://github.com/flutter/engine/pull/56949#discussion_r1871750266

This jsfiddle allows reproducing the bug:
https://jsfiddle.net/knevercode/y2hpfmrb/2/

On the following recording, you can see the events' targets and their
bounding boxes.
<video
src="https://github.com/user-attachments/assets/82af8d86-2cfe-4e36-a977-46ffa58facdb"/>

Those coalesced events have their `offsetX` and `offsetY` values
relative to the dummy `div` target. So to fix that, we have to translate
those values to be relative to the actual target.

This PR does exactly this in `_computeOffsetForInputs` when
`event.target != eventTarget` .

| Before | After |
| - | - |
| https://chrome-input-selection-bug.web.app |
https://chrome-input-selection-fix.web.app |
| <video
src="https://github.com/user-attachments/assets/1e10b43a-ff4f-46e8-8977-ee435f9d78fb"/>
| <video
src="https://github.com/user-attachments/assets/a997bfd0-8361-4bb3-910c-58cfc6b5d426"/>
|

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
parent 3315c123
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment