Unexpected peer cursor position after line break #554
-
When I ran the repository's Playground locally and tried out its collaborative editing feature, I noticed that the focus did not match my expectations in the situation shown in the image below. I haven't yet delved into the code in the repository, but was this the intended result? My guess is that this issue occurs because the Enter operation first deletes the node in the first line and then inserts it in the second line, causing the position of the collaborator to be associated with a deleted data structure and therefore unable to be accurately located. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for your feedback. It's an excellent question about how BlockSuite works! As a block-based framework, BlockSuite models different blocks into different objects (Y.Map under the hood). So for paragraphs, each paragraph block holds a different Y.Text instance. When you perform a line break, we split the paragraph into two paragraphs so they hold different text instances. After splitting, the right-hand part of the existing paragraph will be deleted. But the peer cursor still references this block. Instead of losing the cursor or throwing an index error, we use the RelativePosition to transform that previous index to a reasonable one, which is the end of the existing block. As an example, suppose I'm going to do a line break at 🖍️, and your cursor locates at 🖌️:
After the line break, there will be two blocks, and your cursor stays at the first one:
That's how the line break and cursor work in BlockSuite for now. I would say this is the expected behavior for the current implementation, but as you point out, this could be unclear sometimes. I can keep this issue open for possible improvements we can make here. |
Beta Was this translation helpful? Give feedback.
Thanks for your feedback. It's an excellent question about how BlockSuite works!
As a block-based framework, BlockSuite models different blocks into different objects (Y.Map under the hood). So for paragraphs, each paragraph block holds a different Y.Text instance. When you perform a line break, we split the paragraph into two paragraphs so they hold different text instances.
After splitting, the right-hand part of the existing paragraph will be deleted. But the peer cursor still references this block. Instead of losing the cursor or throwing an index error, we use the RelativePosition to transform that previous index to a reasonable one, which is the end of the existing block.
As an exam…