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

Collab Highlight #141

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
};

OrionSocketAdapter.prototype.constructor = OrionSocketAdapter;

/**
* Send authenticate message
*/
Expand Down Expand Up @@ -307,6 +307,7 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function

case 'client-left':
this.collabClient.removePeer(msg.clientId);
this.collabClient.textView._removePeerHighlight(msg.clientId);
break;

default:
Expand Down Expand Up @@ -574,7 +575,7 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
};

OrionEditorAdapter.prototype.getSelection = function () {
return ot.Selection.createCursor(this.editor.getSelection().start);
return new ot.Selection([new ot.Selection.Range(this.editor.getSelection().start, this.editor.getSelection().end)]);
};

OrionEditorAdapter.prototype.setSelection = function (selection) {
Expand Down Expand Up @@ -608,15 +609,6 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
var lastLine = this.model.getLineCount()-1;
var lineStartOffset = this.model.getLineStart(currLine);

if (offset) {
//decide whether or not it is worth sending (if line has changed or needs updating).
if (currLine !== this.myLine || currLine === lastLine || currLine === 0) {
// Send this change
} else {
return;
}
}

this.myLine = currLine;

// Self-tracking
Expand All @@ -630,7 +622,12 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
if (this.changeInProgress) {
this.selectionChanged = true;
} else {
this.trigger('selectionChange');
if(!this.editor._listener.mouseDown){
// Trigger 'selectionChange' (send messges) only if mouse is up.
// This prevents from sending multiple messages
// while user is selecting.
this.trigger('selectionChange');
}
}
};

Expand All @@ -646,7 +643,10 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
var peer = this.collabClient.getPeer(clientId);
var name = peer ? peer.name : undefined;
color = peer ? peer.color : color;

this.updateLineAnnotation(clientId, selection, name, color);
this.updateHighlight(clientId, selection, name, color);

var self = this;
return {
clear: function() {
Expand All @@ -655,6 +655,13 @@ define(['orion/collab/collabPeer', 'orion/collab/ot', 'orion/uiUtils'], function
};
};

OrionEditorAdapter.prototype.updateHighlight = function(id, selection, name, color, force) {
// Extracting 'highlight' information out of 'selection' object
var ranges = selection.ranges[0];

this.collabClient.textView._addHighlight(id, color, ranges.anchor, ranges.head);
}

OrionEditorAdapter.prototype.updateLineAnnotation = function(id, selection, name, color, force) {
force = !!force;
name = name || 'Unknown';
Expand Down
Loading