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 pasting in composition mode #599

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

Conversation

QichenZhu
Copy link
Contributor

@QichenZhu QichenZhu commented Jan 16, 2025

Details

Issues

In the web example app, pasting doesn’t work after typing with Samsung keyboard.

In Expensify app, pasting works, but the caret position is wrong in the case of issue Expensify/App#40025.

Cause

When pasting, mobile browsers don’t fire the compositionend event, so the component handles the pasting event in composition mode,

if (compositionRef.current) {
updateTextColor(divRef.current, parsedText);
updateSelection(e, {
start: newCursorPosition,
end: newCursorPosition,
});
divRef.current.value = parsedText;
if (onChangeText) {
onChangeText(parsedText);
}
return;
}

and the normal process doesn’t execute.

newInputUpdate = parseText(parser, divRef.current, parsedText, processedMarkdownStyle, newCursorPosition, true, !inputType, inputType === 'pasteText');

Solution

This PR fixes the issue by detecting composition mode with the isEventComposing() function.

Related Issues

Expensify/App#40025

PROPOSAL: Expensify/App#40025 (comment)

Manual Tests

Precondition: Use a soft keyboard in composition mode, such as Samsung keyboard with autocorrection enabled.

  1. Launch the web example app in Android Chrome.
  2. Copy some text.
  3. Clear the textbox.
  4. Type "aaa".
  5. Long press the caret until the context menu pops up.
  6. Tap Paste.
  7. Verify that the copied text pastes into the textbox.
Before After
before.mp4
after.mp4

Linked PRs

@tomekzaw
Copy link
Collaborator

tomekzaw commented Jan 16, 2025

Hi @QichenZhu, thanks for the PR. I don't have much expertise in the web part of Live Markdown so I'll just pass it to someone else from the team who will review your PR shortly.

Looks like web E2E test is failing, could you please fix it as well?

@QichenZhu QichenZhu marked this pull request as ready for review January 16, 2025 11:47
@QichenZhu
Copy link
Contributor Author

Thanks for your help! I’m open to any suggestions or alternative approaches.

Web E2E testing has passed.

Copy link
Collaborator

@BartoszGrajdek BartoszGrajdek left a comment

Choose a reason for hiding this comment

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

Overall looks good, I've tested it against most of the similar issues we've had like voice recognition, diacritics, GBoard and such - on safari, firefox and chromium 👍🏻

I still need to test it with a Samsung phone though, ideally a physical device, so I'll be doing that tomorrow when I get a hold of a phone with Samsung keyboard.

Changing anything related to composition is tricky, since we've had some regressions related to that in the past, hence the throughout testing 😓

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.

3 participants