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

onValueChange not triggered when selecting text from right to left then paste #5814

Open
gwy15 opened this issue Mar 6, 2025 · 1 comment
Labels

Comments

@gwy15
Copy link

gwy15 commented Mar 6, 2025

Description
For slate react, onValueChange is not triggered when

  • select all content from right to left, then do a ctrl+v/cmd+v paste

Recording

Image

Sandbox
https://codesandbox.io/p/devbox/slate-reproductions-forked-jc6pq2?workspaceId=ws_Pbq92KWBCGm3cg9fGwjBFV

Steps
To reproduce the behavior:

  1. Go to https://codesandbox.io/p/devbox/slate-reproductions-forked-jc6pq2?workspaceId=ws_Pbq92KWBCGm3cg9fGwjBFV
  2. Copy some random text in your clipboard
  3. Select all text in slate editor from right to left,
  4. Do a cmd+v/ctrl+v paste
  5. The onValueChange callback is not triggered!

Expectation
Since pasting value does change the value, onValueChange should be triggered.

As a matter of fact,

  • select text from left to right, then paste
  • cmd+a select all, then paste
    works fine, only select from right to left then paste does not work XD

Environment

  • Slate Version: latest (0.112)
  • Operating System: macOS
  • Browser: Chrome
@gwy15 gwy15 added the bug label Mar 6, 2025
@doonazif
Copy link

doonazif commented Mar 8, 2025

This also happens to me.

Seems like, in this switch, the set_selection is passed as the options.operation.type when typing after selecting from right to left.

I didn't check it thoroughly but it can easily be checked by:

  • listening to both onSelectionChange and onValueChange
  • select right to left, then type a character
  • the onSelectionChange is called when typing the 1st character (this is not expected)
  • now select from left to right, then type a character
  • the onValueChange is called when typing the 1st character (this is expected and should also be the case for the above scenario)

I can use onChange instead of onValueChange but onChange is called profusely (selecting, moving cursor, typing, etc) and I tried to avoid that because of the many side-effects that my component will create when a text change.

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

No branches or pull requests

2 participants