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 MacOS long-press accented char bug #3041

Closed
wants to merge 2 commits into from

Conversation

knubie
Copy link
Contributor

@knubie knubie commented Sep 28, 2019

Is this adding or improving a feature or fixing a bug?

bug

What's the new behavior?

See #982 for details on the bug.

Screen Shot 2019-10-06 at 1 03 11 PM

How does this change work?

The change works by trying to guess when an insertion from the popover is occurring. It does this by comparing the last keyDown value with the value of onBeforeInput (which is triggered after a selection is made). If the values are different, and the last keyDown value was a number between 1-9, and the text for onBeforeInput falls within the unicode range of an accented character, it will insert the character at the specified range. The range is specified as the current selection, with the focus moved back one character, thereby replacing the non-accented character that was inserted when the long press was initiated.

Have you checked that...?

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn prettier.)
  • The relevant examples still work. (Run examples with yarn watch.)

Does this fix any issues or need any specific reviewers?

Fixes: #982
Reviewers: @ianstormtaylor

@ianstormtaylor
Copy link
Owner

Hey @knubie thanks for the writeup here, helps to understand!

Do the native browser events that are being fired not ever expose selection-related information? I would have assumed that there might be a composition* or beforeinput event that had a Range associated with it telling us where the delete should occur?

@knubie
Copy link
Contributor Author

knubie commented Oct 6, 2019

Thanks for taking a look @ianstormtaylor

I wasn't able to find any useful range info for Chrome or Firefox, but it's possible that I could have overlooked something (or just don't know where to look). Here's a more detailed breakdown of my findings:

Chrome

Fires onBeforeEvent (synthetic, nativeEvent is TextEvent)
Couldn't find any useful range info here.

Firefox

Fires onBeforeEvent (synthetic, nativeEvent is compositionend)
Couldn't find any useful range info here.

Fires onCompositionEnd (synthetic, nativeEvent is compositionend)
Couldn't find any useful range info here

Safari

Fires onBeforeEvent (native)
event.getTargetRanges() //=> {startOffset: 0, endOffset: 1, ...}

@knubie
Copy link
Contributor Author

knubie commented Oct 6, 2019

Also worth noting that insertion was completely broken on non-MacOS environments before my last commit (b12ae54), but it doesn't look like the CI tests were able to catch that.

@ianstormtaylor
Copy link
Owner

Fixed by #3093.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[IME] FF/macOS: entering accented letters from the Accent Menu inserts double character
2 participants