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

editor.insertText never gets called inside plugins on android #4709

Closed
fridaystreet opened this issue Dec 3, 2021 · 5 comments · Fixed by #4753 or #4779
Closed

editor.insertText never gets called inside plugins on android #4709

fridaystreet opened this issue Dec 3, 2021 · 5 comments · Fixed by #4753 or #4779

Comments

@fridaystreet
Copy link

fridaystreet commented Dec 3, 2021

Description
if you create a withMyPlugin and have it override the editor.insertText function, the function is never called when inserting text on an android device

Steps
create a plugin and override the editor.insertText function, console.log the output, it never gets called on android

Expectation
the editor.insertText function is called like other functions when user enters text on andorid

Environment

  • Slate Version: latest
  • Operating System: android
  • Browser: Chrome
@fridaystreet fridaystreet changed the title editor.insertText in never fires inside plugins editor.insertText in never fires inside plugins on android Dec 3, 2021
@fridaystreet fridaystreet changed the title editor.insertText in never fires inside plugins on android editor.insertText never gets called inside plugins on android Dec 3, 2021
@fridaystreet
Copy link
Author

sorry not sure why the cross platform label was added, I did choose bug for specific platform

@alessiogaldy
Copy link
Contributor

I took a look at this issue, and if I change this line

Transforms.insertText(editor, text, {
to call Editor.insertText, the plugins work again.
I am unsure if this is the correct fix because I don't know when Editor.insertText should be used instead of Transforms.insertText. The regular Editable component uses both.
I hope this helps narrow down the issue 🤞

@dylans
Copy link
Collaborator

dylans commented Dec 30, 2021

sorry not sure why the cross platform label was added, I did choose bug for specific platform

fwiw, I think the label gets applied when something breaks cross-platform compatibility.

@dylans
Copy link
Collaborator

dylans commented Dec 30, 2021

I took a look at this issue, and if I change this line

Transforms.insertText(editor, text, {

to call Editor.insertText, the plugins work again.
I am unsure if this is the correct fix because I don't know when Editor.insertText should be used instead of Transforms.insertText. The regular Editable component uses both.
I hope this helps narrow down the issue 🤞

Editor.insertText simply calls this: https://github.com/ianstormtaylor/slate/blob/main/packages/slate/src/create-editor.ts#L169-L182 which checks for a selection and if the selection contains marks. If no selection it does nothing, if selection contains marks, it calls Transforms.insertNodes, or if no marks, it calls Transforms.insertText.

So yes, overriding Editor.insertText will get ignored since the underlying code calls Transforms.insertText in both the Android and non-Android Editable code.

My suggestion would be to raise a PR that replaces the Transforms calls with Editor so that all calls with the React editor can be extended/overridden consistently. I'm happy to review a PR or work on it when time permits.

@fridaystreet
Copy link
Author

@alessiogaldy @dylans thanks so much for sorting this out

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