yorkie-team / yorkie-js-sdk

Yorkie JavaScript SDK
https://yorkie.dev/docs/js-sdk
Apache License 2.0
137 stars 91 forks source link

Remote selection is not maintained in quill example #553

Closed chacha912 closed 5 months ago

chacha912 commented 1 year ago

What happened:

In the quill example, when editing before a remote cursor, the remote cursor position is not maintained.

What you expected to happen:

Regardless of local edits, the remote cursor or selection should be preserved.

How to reproduce it (as minimally and precisely as possible):

quill-bug

1) ClientB selects 12. When ClientA enters text before 12, the selection for 12 is not maintained.

2) ClientB places the cursor after 3. When ClientA enters text before 3, ClientB's cursor position is not maintained.

Anything else we need to know?:

Related #348

Environment:

ed-jinyoung-park commented 1 year ago

I'll try fix this 🙂

ed-jinyoung-park commented 1 year ago

<--- For record keeping ---->

i am trying to update Selection on remote edit operation triggered

const from = op.from;
...
const index = quill.getSelection().index;
const length = quill.getSelection().length;

if(from <= index){
    quill.setSelection(index + insert.length, length, 'user');
}

and expect the setSelection to trigger set presence which is included in selection-change event callback.

it works, but problem is it seems to trigger setSelection twice. and i don't know why. maybe setSelection by user triggers setSelection one more by api (https://quilljs.com/docs/api/#setselection)

Jul-29-2023 18-37-48

1.ClientA selects 123.

  1. When ClientB enters text before 123, remote selection is maintained in 123 but in ClientA selection goes to 234. it moves on more index than expected.
chacha912 commented 1 year ago

@ed-jinyoung-park, thank you for taking on this issue!

Have there been any updates since the last comment? If the problem continues, could you provide a draft PR or share the working branch so that we can try running the code? This would enable us to know which version of Yorkie you're testing with and where the issue is occurring.

ed-jinyoung-park commented 1 year ago

@chacha912 thanks for suggestion. i'll try to share draft PR soon.