Permalink
Browse files

Implment backspace

  • Loading branch information...
pksunkara committed Sep 18, 2011
1 parent c2ba938 commit 0eda54d5b95f9c30ed232fe6ef2bdc1f82f2e43d
Showing with 10 additions and 2 deletions.
  1. +5 −1 app.js
  2. +5 −1 public/javascripts/collab.js
View
6 app.js
@@ -90,7 +90,11 @@ io.sockets.on('connection', function(socket){
tmp.cursor += history[i].len;
}
data.cursor = tmp.cursor;
- codeToCollab = codeToCollab.substr(0,data.cursor-1) + data.edit + codeToCollab.substr(data.cursor-1+data.edit.length);
+ if(data.edit=='\b') {
+ codeToCollab = codeToCollab.substr(0,data.cursor-1) + codeToCollab.substr(data.cursor);
+ } else {
+ codeToCollab = codeToCollab.substr(0,data.cursor-1) + data.edit + codeToCollab.substr(data.cursor);
+ }
docVersion += 1;
history.push(tmp);
io.sockets.emit('edit', data);
@@ -64,7 +64,11 @@ key_handler = function (event) {
socket.on('edit', function (data){
var text = acee.getSession().getValue();
- text = text.substr(0,data.cursor) + data.edit + text.substr(data.cursor-1+data.edit.length);
+ if(data.edit == '\b') {
+ text = text.substr(0,data.cursor-1) + text.substr(data.cursor);
+ } else {
+ text = text.substr(0,data.cursor) + data.edit + text.substr(data.cursor);
+ }
docVersion += 1;
acee.getSession().setValue(text);
setCursor(data.cursor);

0 comments on commit 0eda54d

Please sign in to comment.