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

[IME] Strange selection behaviour when writing before a mark #2958

Closed
gracicot opened this issue Aug 5, 2019 · 3 comments
Closed

[IME] Strange selection behaviour when writing before a mark #2958

gracicot opened this issue Aug 5, 2019 · 3 comments

Comments

@gracicot
Copy link
Contributor

gracicot commented Aug 5, 2019

Do you want to request a feature or report a bug?

Bug

What's the current behavior?

The selection is moving at the start of the inputted text/letter when writing just before a mark. It only happen on Adroid.

I tested with Chrome android and chrome keyboard.

Here's a gif:
https://imgur.com/a/MfqlnfD

Code sandbox link

With a minimal slatejs setup, we were also able to reproduce the issue.

Due to how our app is made, a mark is almost always at the end so it happens all the time, crippling text writing.

What's the expected behavior?

The selection should be stable when writing

@gracicot
Copy link
Contributor Author

gracicot commented Aug 8, 2019

I investigated the bug, and it seem to come from the findPoint function.

When typing into the editor, android write the text into the slate-zero-width span element.

That element contains text &#65279. But the element is then discarded from the text:

Array.from(zeroWidths).forEach(function (el) {
    el.parentNode.removeChild(el);
});

The entered text is discarded and the offset is set to 0.

Later in the code, I see:

// COMPAT: If the parent node is a Slate zero-width space, this is because the
// text node should have no characters. However, during IME composition the
// ASCII characters will be prepended to the zero-width space, so subtract 1
// from the offset to account for the zero-width space character.
if (offset === node.textContent.length && parentNode.hasAttribute(DATA_ATTRS.ZERO_WIDTH)) {
    offset--;
}

But with the logic above, I don't see how that can be executed, since a zero width is contained in a span with no attribute, then contained in a slate leaf element.

@gracicot
Copy link
Contributor Author

gracicot commented Aug 8, 2019

With further investigations, I saw that normalization also set the offset to 0.

The node returned by node.getNode(path) report no text inside.

I think the issue is because the text is entered in the wrong element inside the document. It should not write into the zero width node.

Anyway, I refer this issue: #2368 since it only happen in android.

I'm willing to give more information if necessary.

@ianstormtaylor
Copy link
Owner

I believe that this may be fixed by #3093, which has changed a lot of the logic in Slate and slate-react especially. I'm going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

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

No branches or pull requests

2 participants