Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selection shifting when deleting paragraphs on android #7239

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

waynetee
Copy link
Contributor

@waynetee waynetee commented Feb 24, 2025

Description

Fixes #4340

This is a second attempt to fix the abovementioned bug, following the unsuccessful attempt in #7122 (apologies for the issues introduced then)

In this PR, selection is only restored during deletion and when several other criteria have been met, this should minimise the chances of any unintended side effects.

Test plan

Before

screen-20250224-160048.mp4

After

screen-20250224-160326.mp4

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 24, 2025
Copy link

vercel bot commented Feb 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2025 5:26am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2025 5:26am

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ideal approach here is to come up with a solution that does not depend on setTimeout. This kind of solution causes a lot of trouble down the line with debugging, possibly creating extra history entries, etc. even when it does work.

@waynetee
Copy link
Contributor Author

@etrepum I agree with you that in a ideal world we would not need to use to use setTimeout. I did spend a significant amount of time investigating this issue and as far as I can tell originates from the browser, making a clean fix difficult.

I see a few ways forward:

  1. We merge this PR
  2. Rather than using setTimeout in the beforeinput handler, we apply the fix in the selectionchange handler. This is workable, but requires a way to sync it to the deletion event. We would likely end up with a fix not much cleaner than this and might end up having to use setTimeout anyways.
  3. We solve the problem in the browser itself, this would be ideal, but it doesn't seem like any progress has been made on the issue since it was filed early last year https://issues.chromium.org/issues/331320419
  4. You or someone else volunteers to investigate this issue to try to come up with a better fix. I would be happy to assist in this case.

I personally think this is a significant bug, it would be good if we can resolve it in a timely manner.

@etrepum
Copy link
Collaborator

etrepum commented Feb 24, 2025

Approach 2 is preferable. I understand that you’ve spent a lot of time investigating, but this type of solution only makes things worse the next time something has to be investigated. Untangling the selection implicit state machine is something on my list but I can’t make any commitments on timing. As you know, this is not simple.

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell with a Google Pixel 5 on Sauce Labs this build still has the bug

@waynetee
Copy link
Contributor Author

Turns out the fix was skipped over by an earlier optimisation in certain cases. It should be fixed now, and I have tested it on both Pixel and Samsung, and with the SwiftKey keyboard too.

Thanks for helping to test this thoroughly.

@waynetee waynetee requested a review from etrepum February 26, 2025 05:34
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with the Pixel and Samsung devices I tried on browser stack with the google, samsung and microsoft keyboards. Does anyone else want to give this a test before merge? /cc @zurfyx @potatowagon

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: When deleting text with the keyboard of a device it's also removing text to the right of the pointer.
3 participants