-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Prosemirror SelectedNode Issue #43
Comments
I believe we can solve this here: const restoreRelativeSelection = (tr, relSel, binding) => {
if (relSel !== null && relSel.anchor !== null && relSel.head !== null) {
const anchor = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.anchor, binding.mapping)
const head = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.head, binding.mapping)
if (anchor !== null && head !== null) {
tr = tr.setSelection(TextSelection.create(tr.doc, anchor, head))
}
}
} |
Hi @akashkamboj, could you please create a PR with the change? If it doesn't break anything, I'm happy to merge it after I was able to test it. |
We are seeing an error in this same function that is causing YJS to pickup an empty change and effectively wipe out our document by persisting it (TipTap + YJS client with Hocuspocus YJS server). Any chance these are related? We've noticed this more when someone has a tab open with the document and comes back online after closing their laptop lid. |
@akashkamboj Did you ever find a workaround to this? We're seeing issues with NodeSelections turned into TextSelections as well, notably our drag handle implementation that lets you move an entire node. We set the NodeSelection so that Prosemirror-view's drop handler will correctly delete the node on drop, but the NodeSelection turns into a TextSelection if someone else edits while youre dragging. |
Have the same issue. I think on any change all node selections are converted to text selections. Not sure how to fix but assume it's related to the restoreRelativeSelection function. Perhaps if the original selection is a node then leave it as is? |
@jamesopti I'm seeing the same issue with the same setup (TipTap + YJS client with Hocuspocus YJS server). Did you have any luck fixing this? For now I've patched y-prosemirror to not call |
@dmonad Any thoughts on this one? We've realized this makes collaborative editing with atom nodes (like an image) impossible as whenever user1 types, user2 loses their selection of the image. |
I just threw up #118 after testing locally and verifying that my selected NodeView remains selected when another user types. |
hi @jamesopti I also did same kind of code to fix it temporarily . But this is not sufficient. Because apart from TextSelection and NodeSelection I also have CellSelection etc. And that becomes a bit complicated to calculate anchor and head. |
For CellSelection, what worked for me is: // oldState is old EditorState, tr is Transaction dispatched by y-prosemirror
if (oldState.selection instanceof CellSelection) {
tr.setSelection(CellSelection.create(tr.doc, tr.selection.$anchor.before(), tr.selection.$head.before()));
} |
here's my solution: hamflx@2ed27a0 features:
Use Use the recorded For custom |
@hamflx awesome work, it's working great. They should really merge it. One more question can we utilize the same in cursors as well somehow. So that if a node is selected the collaborator can see the selection as an overlay over the node? |
I checked everywhere and there is no solution to it.
Describe the bug
Prosemirror provides the ability to create NodeSelection. But when content is updated through YJS. The node selection gets removed and become the TextSelection.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Ideally it should retain the NodeSelection and not convert it to TextSelection.
Environment Information
Everywhere
Additional context
I can detect the changes and move TextSelection back to NodeSelection, that requires an additional update to the state and behaviour will not be smooth at all. That doesn't seem the right way to me. Ideally y-prosemirror should handle this scenario itself.
The text was updated successfully, but these errors were encountered: