Permalink
Browse files

Fix line

  • Loading branch information...
1 parent 4ca89fc commit d5288205196637e59a02ec224f04072e8bd471ee @pksunkara committed Sep 18, 2011
Showing with 22 additions and 4 deletions.
  1. +22 −4 public/javascripts/collab.js
@@ -25,9 +25,9 @@ sendChat = function() {
}
getCursor = function() {
- cursor = $('.ace_cursor')[0];
- linem1 = parseInt(cursor.style.top.replace('px',''))/18;
- column = (parseInt(cursor.style.left.replace('px',''))-4)/7;
+ cursor = acee.getCursorPosition();
+ linem1 = cursor.row;
+ column = cursor.column;
text = acee.getSession().getValue().split("\n");
pos = 0;
for(i=0;i<linem1;i++) {
@@ -36,6 +36,23 @@ getCursor = function() {
return pos+column;
}
+setCursor = function(val) {
+ var text = acee.getSession().getValue();
+ var linem1 = 0;
+ var column = 0;
+ for(i=0;i<val;i++) {
+ if(text[i]=="\n") {
+ linem1++;
+ column = 0;
+ } else
+ column++;
+ }
+ acee.gotoLine(linem1+1);
+ var cursor = $('.ace_cursor')[0];
+ console.log("Column - " + column);
+ cursor.style.left = (column*7+4)+'px';
+}
+
key_handler = function (event) {
var key = event.which || event.keyCode;
if(noNeed.indexOf(key)==-1 && !(event.altKey || event.ctrlKey)) {
@@ -47,9 +64,10 @@ key_handler = function (event) {
socket.on('edit', function (data){
var text = acee.getSession().getValue();
- text = text.substr(0,data.cursor-1) + data.edit + text.substr(data.cursor-1+data.edit.length);
+ text = text.substr(0,data.cursor) + data.edit + text.substr(data.cursor-1+data.edit.length);
docVersion += 1;
acee.getSession().setValue(text);
+ setCursor(data.cursor);
});
socket.on('version', function(data){

0 comments on commit d528820

Please sign in to comment.