Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two issues with remote caret.
Screen.Recording.2022-07-04.at.2.12.03.AM.mov
Screen.Recording.2022-07-04.at.2.15.53.AM.mov
Since currently, we store relative position for cursors, awareness doesn't get updated when the cursor is moved while typing. This causes the second issue. To fix that, I've refactored the code to also save
Codemirror.Position
information insidecursors
set inheadpos
key. And any time doc's state changes, we compare the before and afterheadpos
, and update the position accordingly.I've used
cm.addWidget
instead ofcm.setBookmark
(as done previously) because bookmarks are inserted as children to.Codemirror-line
node. However, all.Codemirror-line
nodes havez-index: 2
. This causes the DOM node that occurs first in the DOM tree to have a higher stacking context. This means, when we position tooltip to be below the current line, it'll appear behind the next line.Demo
Screen.Recording.2022-07-04.at.2.22.18.AM.mov
Known Issue
Because we only store relative position of cursors, and because in
typeObserver
function we don't really know which user made that change, we rely on comparing before and afterheadpos
. This however has its limitations. Consider the scenario where user A and user B are collaborating. The text is1234
. A's cursor is between 3 and 4. Now, B inserts something before1
. Then, A's tooltip will be shown to B, even though A has not typed anything. This is because when users are collaborating on the same line, then any changes to that line will also changech
key ofheadpos
.