Browse files

Merge branch 'master' of github.com:pkumar/codecollab

  • Loading branch information...
2 parents 042c177 + e73360d commit 8a61822f15f47de3c9aa3ecc3da5544d2fca7c2f @pksunkara committed Sep 18, 2011
Showing with 19 additions and 5 deletions.
  1. +4 −1 app.js
  2. +15 −4 public/javascripts/collab.js
View
5 app.js
@@ -97,7 +97,10 @@ io.sockets.on('connection', function(socket){
}
docVersion += 1;
history.push(tmp);
- io.sockets.emit('edit', data);
+
+ socket.get('nickname', function(err, nickname) {
+ io.sockets.emit('edit', {d:data, n:nickname});
+ });
});
});
View
19 public/javascripts/collab.js
@@ -62,16 +62,26 @@ key_handler = function (event) {
}
}
+
socket.on('edit', function (data){
var text = acee.getSession().getValue();
- if(data.edit == '\b') {
- text = text.substr(0,data.cursor-1) + text.substr(data.cursor);
+ var currentCursor = getCursor();
+ if(data.d.edit == '\b') {
+ text = text.substr(0,data.d.cursor-1) + text.substr(data.d.cursor);
} else {
- text = text.substr(0,data.cursor) + data.edit + text.substr(data.cursor);
+ text = text.substr(0,data.d.cursor) + data.d.edit + text.substr(data.d.cursor);
}
+
docVersion += 1;
acee.getSession().setValue(text);
- setCursor(data.cursor);
+
+ socket.get('nickname', function(err, nickame){
+ if(data.n == nickname){
+ setCursor(data.d.cursor);
+ } else {
+ setCursor(currentCursor);
+ }
+ });
});
socket.on('version', function(data){
@@ -82,6 +92,7 @@ socket.on('version', function(data){
socket.on('nickname?', function(data){
var nickname = prompt('Your nickname?');
socket.emit('nickname', nickname);
+ socket.set('nickname', nickname);
socket.on('members', function(data){
members = data;
updateMembers();

0 comments on commit 8a61822

Please sign in to comment.