Skip to content
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

Show remote carets #23

Merged
merged 2 commits into from
Apr 29, 2017
Merged

Show remote carets #23

merged 2 commits into from
Apr 29, 2017

Conversation

Worie
Copy link
Collaborator

@Worie Worie commented Apr 29, 2017

Here we go. I tried to follow your codestyle, I guess it should be ok. The changes provided should cover every input from peers (multiple carets, removals, additions, pastes and cuts)

If this PR's alright, then in the future I guess we should create a html template for carets (for future features such as displaying the carets owner name and for code maintenance purposes)

This solves #22

@Worie
Copy link
Collaborator Author

Worie commented Apr 29, 2017

Just realized that it works well when there are only two peers, but fails with more than that.

The problem is that upon recieving the change event, the remoteCarets set is being cleared.

So in scenario:

  1. Peer A connects
  2. Peer B connects
  3. Peer C connects
  4. Peer B moves his caret
  5. Peer A and C sees it
  6. Peer C moves his caret.
  7. Peer A loses the state of peer B caret.

So, each peer should have probably his own Set().

main.js Outdated
newEditor._codeMirror.on('change', sendLocalChange)
newEditor._codeMirror.on('beforeSelectionChange', sendLocalSelect)
newEditor._codeMirror.on('change', onCodeChange)
newEditor._codeMirror.on('changes', onCodeChanges)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to start listening to operation-batched changes, we should only use the 'changes' event.

return range.head.ch !== range.anchor.ch || range.head.line !== range.anchor.line
}

function sendLocalCaretsMoves (cm, change) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a few comments to this to explain how you are calculating the caret positions from the changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll sit to it when finish your review :)

main.js Outdated
@@ -396,13 +450,30 @@ define(function (require, exports, module) {
})
}

function handleRemoteCarets (data) {
if (fromWebPath(data.filePath) !== documentRelativePath) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now, but add a TODO so we can support tracking carets in closed files. (Needs to be done for selections to if I remember correctly.)

@t-mullen
Copy link
Member

t-mullen commented Apr 29, 2017

Looks good, thanks for figuring this out. I added a few comments.

main.js Outdated
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
var nickname = null
var knownDocs = {}
var room
var remoteCarets = new Set()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use ES6 anywhere else. Please use an object set and use keys to iterate.

Copy link
Member

@t-mullen t-mullen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind. YJS integration will take too long.

Please make the requested style changes and I'll run some tests.

@Worie
Copy link
Collaborator Author

Worie commented Apr 29, 2017

Guess that's it. Besides the requested changes I've left a comment about the issue I mentioned in #23 (comment) earlier.

@t-mullen
Copy link
Member

OK, seems to be working great aside from the issue with >2 users. I'll fix that in a later commit when I do cursor colours. Thanks @Worie !

Would you like to be added as a maintainer? I can always use some more help developing this :)

@t-mullen t-mullen merged commit 4872c55 into multihack:master Apr 29, 2017
@Worie
Copy link
Collaborator Author

Worie commented Apr 30, 2017

I'm glad it's ok :) When it comes to me as a maintainer - I can't really promise anything as I don't know how much spare time will I have, but sure - that'd be nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants