-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Cursor set to the end of text after each update #2216
Comments
I can’t reproduce this. Not sure if it has something to do with |
@nomadus I have the same issue, did you ever fix this? |
Yes, I fixed, but I don't remember what exactly I did. Here is the latest code, which is different from the original one, maybe it will help?
|
you absolute beauty! This should be in the docs for people who are using the "controlled component" paradigm with React. Thank you so much for sharing! |
YES! thanks! |
Except this still needs a "magic-number" throttle/debounce because at fast enough input rates your render loop still gets out of sync. Your magic-number will vary based on the performance of your device and your time to render, but although this approach goes a long way to addressing the problem, it still gets overwhelmed at the extreme. It's not a fix. |
Brother, you are a life saver... Thanks for the code snippet |
Fix provided by @nnurmano works (ty!), but @nullpaper brings up a good point. Maybe there's a better way to support controlling the editor content. I searched around and couldn't find anything. Can this issue be re-opened? Or is there a more generic "react responsivity/control" issue or solution? |
Could https://react.dev/reference/react/useDeferredValue be used to mitigate nullpaper's point? |
Instead of using setContent, you can use insertContent, that does not replace the whole content, just insert the new content and doesn't move the cursor at the end of the content, just at the end of insertion. And you don't need to use the component in a "controlled" way at all. You can just update the state on blur, for example. It's much faster and you don't need to debounce it. |
…ioning in Tiptap editor Related to: ueberdosis/tiptap#873, ueberdosis/tiptap#2216
Hi Guys, The solution you proposed works but has a limitation: if you change the value outside the component and the value in the editor is not empty, it doesn't update. The problem, as you mentioned, is that const isSame = editor.getHTML() === newValue;
if (isSame) {
return;
} I wondered why it wasn't entering the if statement, so I investigated and discovered that getHTML() converts special characters while in newValue I found values like Ù, Œ, etc. To correct this error, you need to replicate what getHTML() does. So the solution I found is this: const div = document.createElement('div');
div.innerHTML = newValue;
const isSame = editor.getHTML() === div.innerHTML;
if (isSame) {
return;
}
editor.commands.setContent(newValue, false); That's why the problem doesn't always occur. |
This code helped me a lot but there is still an issue when using ordered list or bullet list it's not working as expected ! Id doesn't insert a number or a bullet but some kind of line break ! Do you have an idea to fix this or why this his happening ? |
Hey man, this is insane, it helped me fixing the issue in my case. Thanks:)) |
Thank you so much! :) |
What’s the bug you are facing?
I updated TipTap to the latest version and now the cursor sets to the end of the text whenever I update.
Here are the details:
How can we reproduce the bug on our side?
I guess yes,
Here are the version details
"@tiptap/extension-highlight": "^2.0.0-beta.30",
"@tiptap/extension-placeholder": "^2.0.0-beta.44",
"@tiptap/react": "^2.0.0-beta.95",
"@tiptap/starter-kit": "^2.0.0-beta.145",
Can you provide a CodeSandbox?
I shall try
What did you expect to happen?
The cursor should stay where it is
Anything to add? (optional)
No response
Did you update your dependencies?
Are you sponsoring us?
The text was updated successfully, but these errors were encountered: