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

Fixed: for #5162, The beginning of a TextNode with canInsertTextBefore false in … #5363

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

matsuyama-k1
Copy link
Contributor

Fix for #5162

…Asian languages It is not replaced when it is replaced
Copy link

vercel bot commented Dec 10, 2023

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 Dec 10, 2023 8:33am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2023 8:33am

@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 Dec 10, 2023
@matsuyama-k1
Copy link
Contributor Author

matsuyama-k1 commented Dec 10, 2023

When multiple strings are selected at the beginning of a TextNode where $canInsertTextBefore is set to false, and input is made in languages that use composing input methods, such as Japanese and Korean, the text input is not reflected, and the editor does not accept further input until Enter is pressed.

I have addressed this issue. The problem may arise because, in languages that use composing, a COMPOSITION_START_CHAR is automatically entered, resulting in what is interpreted as a two-character input. As I understand it, the onInput function is triggered when a node is created and a second character is input. However, in languages like Japanese, it activates with a single character input.

Therefore, canInsertTextBefore might be inadvertently engaged. Directly preventing the problem when two characters are input was not feasible for me, so I added a condition to the if statement to address this recent issue.

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Thanks!

From a correctness perspective this PR is not great, the canInsertBefore was meant to prevent any input at boundaries which is what you're doing here.

Unfortunately, composition is not flexible, and we can't reposition the cursor when that happens, and with the MutationObserver logic combined is the reason why you're not seeing any text.

I believe the best solution would be to swap DOM nodes but that is something we don't support now and might get tricky with custom extended nodes.

Given that this change improves a11y, I'm inclined to accept it despite the correctness trade-off.

@@ -650,7 +650,8 @@ export function $updateTextNodeFromDOMContent(
prevSelection.anchor.offset === 0) ||
(prevSelection.anchor.key === textNode.__key &&
prevSelection.anchor.offset === 0 &&
!node.canInsertTextBefore()) ||
!node.canInsertTextBefore() &&
!isComposing) ||
Copy link
Member

Choose a reason for hiding this comment

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

Can we do the same on L657 for canInsertTextAfter?

Copy link
Contributor Author

@matsuyama-k1 matsuyama-k1 Dec 12, 2023

Choose a reason for hiding this comment

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

I have inserted the line for canInsertTextAfter and confirmed that the jest tests run correctly. Additionally, I attempted to run the npm run test-e2e-chromium command for end-to-end testing, but the execution time was excessively long, preventing the tests from completing. I haven't encountered any specific scenarios that cause bugs when the line is not inserted within canInsertTextAfter, but it appears to function properly when the line is included.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, yeah, some E2E tests are flaky and take multiple times to pass unfortunately

@zurfyx zurfyx merged commit ee82c4f into facebook:main Dec 12, 2023
42 of 44 checks passed
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants