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

Text input goes backwards after adding a soft break in Chrome #5611

Open
raimohanska opened this issue Mar 1, 2024 · 3 comments
Open

Text input goes backwards after adding a soft break in Chrome #5611

raimohanska opened this issue Mar 1, 2024 · 3 comments

Comments

@raimohanska
Copy link

Description

When using Chrome, soft breaks (line feed characters) and formatting such as bold, the editor goes to a mode where the characters you type actually appear in reverse order.

Recording

Here you can see what happens when I press Shift+Enter in a certain position and start typing. All backwards!

slate-bug.mov

Sandbox

https://codesandbox.io/p/sandbox/slate-chrome-bug-d4nzx4

Steps

To reproduce the behavior:

  1. Using Chrome browser, go to the sandbox.
  2. Place caret at the end of the line with a bold text
  3. Press Shift+Enter to add a soft break
  4. Type something. You should see the text you typed appearing backwards.

Expectation

Text should appear as you type it.

Environment

  • Slate Version: 0.102.0
  • Slate-react: 0.102.0
  • Operating System: MacOS
  • Browser: Chrome (Version 122.0.6261.69)

Context

The setup required for reproduction is pretty simple as you can see in the sandbox. If seems to require that you have line breaks (\n) characters in use and that you have some formatting at the end of a line.

@raimohanska
Copy link
Author

I may possibly help with the fix or at least the verification of it, but at the moment am not familiar with any Slate implementation details so I don't even know where to start looking.

@mainhanu
Copy link
Contributor

mainhanu commented Mar 7, 2024

I think this has something todo with the code

editor.insertSoftBreak = () => {
      editor.insertText("\n");
};

if you try to insert \n at the end of an node in a ContentEditable, the browser may behavior wired, add an extra zero width string can fix it。editor.insertText("\n\uFEFF").

you can reference the code at https://github.com/ianstormtaylor/slate/blob/main/packages/slate-react/src/components/string.tsx, I don't quite understand this either.

in your case I think you should use editor.insertBreak() or editor.splitNodes({ always: true })

@raimohanska
Copy link
Author

Adding the zero-width space seems to help indeed. Thanks @mainhanu!

Still this seems like bug to me, even tho the worksround is available.

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

No branches or pull requests

2 participants