pedrosanta/quill-sharedb-cursors

Cursor misplacement on concurrent editing with 'Enter'/new lines

pedrosanta opened this issue · 4 comments

Sometimes, when two or more users are typing and adding new lines/pressing Enter key, it can lead to cursor misplacement/shift off by one, two, etc, positions.

You can replicate this by having two people on this example, one writing forward without entering new lines, and another writing and adding a few new lines. This doesn't occur on the first new line attempts, but after a solid half-dozen or more new lines/enter keypresses by the second person.

Also needs more testing/debugging.

Just added something that can alleviate this issue, added a mechanism that forces a cursor update some time after the user stops typing (and it's debounced): af81b13

It's not ideal, and it's a fix, but it helps the cursor position to heal/re-sync when its position becomes 'dirty'.

It improves #1 too.

@pedrosanta I've noticed the debounce timeout is 1500, but it updates much quicker and works better with lower debounce time, like 100ms. Why did you choose 1500 as the debounce timeout?

@pedrosanta I have also noticed in my console that I get the console.log('Troubles!', cursor) statement reached quite often. But it still appears that the cursor works just fine... Why is this?

@pedrosanta I have also noticed in my console that I get the console.log('Troubles!', cursor) statement reached quite often. But it still appears that the cursor works just fine... Why is this?

That's something I'm still checking out. I have since improved that overly generic logging to a more sensible console.warn. But, I've managed to catch a case or two when that happens – check reedsy/quill-cursors#8.