Fix bug with cursor.

This commit is contained in:
Hugo Lazzari 2013-04-08 15:02:37 -03:00
parent 7c70a0fe86
commit 7addfaf434
2 changed files with 20 additions and 12 deletions

View File

@ -71,8 +71,8 @@ function patchClientText(patches, text, selectionStart, selectionEnd) {
dmp.Match_Threshold = 0.6;
var oldClientText = text
oldClientText = "#12FGKGMENI4873!#isKcJ" + oldClientText + "2OI3nfi#213fcouef*od(1";
var cursor = captureCursor_(oldClientText, selectionStart+22, selectionEnd+22);
oldClientText = oldClientText + "2OI3nfi#213fcouef*od(1";
var cursor = captureCursor_(oldClientText, selectionStart, selectionEnd);
// Pack the cursor offsets into an array to be adjusted.
// See http://neil.fraser.name/writing/cursor/
var offsets = [];
@ -95,12 +95,17 @@ function patchClientText(patches, text, selectionStart, selectionEnd) {
cursor.collapsed = true;
}
}
return [restoreCursor_(cursor, newClientText), newClientText.substring(22,newClientText.length-22)];
//document.write(oldClientText+"<br>");
//document.write(newClientText+"<br>");
//document.write(newClientText.substring(0,newClientText.length-22)+"<br>");
return [restoreCursor_(cursor, newClientText), newClientText.substring(0,newClientText.length-22)];
// this.restoreCursor_(cursor);
}
}
// no change in client text
return [[selectionStart, selectionEnd], newClientText.substring(22,newClientText.length-22)];
return [[selectionStart, selectionEnd], newClientText.substring(0,newClientText.length-22)];
}
/**
@ -303,5 +308,6 @@ function restoreCursor_(cursor, text) {
cursorEndPoint = cursorStartPoint;
}
return [cursorStartPoint-22, cursorEndPoint-22];
return [cursorStartPoint, cursorEndPoint];
}

View File

@ -37,6 +37,7 @@ package org.bigbluebutton.modules.sharednotes.views.components
import flash.events.MouseEvent;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent
import flash.display.InteractiveObject;
public class PatchableTextArea extends TextArea
@ -135,6 +136,7 @@ package org.bigbluebutton.modules.sharednotes.views.components
var oldPosition:Number = getOldPosition();
var oldVerticalPosition:Number = this.verticalScrollPosition;
LogUtil.debug("Initial Position: " + lastBegin + " " + lastEnd);
results = DiffPatch.patchClientText(patch, textField.text, selectionBeginIndex, selectionEndIndex);
if(results[0][0] == lastBegin && results[0][1] > lastEnd) {
@ -152,18 +154,18 @@ package org.bigbluebutton.modules.sharednotes.views.components
lastEnd = results[0][1];
}
this.text = results[1];
this.validateNow();
LogUtil.debug("Final Position: " + results[0][0] + " " + results[0][1]);
LogUtil.debug("Remote Position: " + beginIndex + " " + endIndex);
LogUtil.debug("Length: " + this.text.length);
this.selectionBeginIndex = lastBegin;
this.selectionEndIndex = lastEnd;
this.validateNow();
LogUtil.debug("Length: " + this.text.length);
restoreCursor(lastEnd, oldPosition, oldVerticalPosition);
this.validateNow();
textField.selectable = true;
textField.stage.focus = InteractiveObject(textField);
textField.setSelection(lastBegin, lastEnd);
this.validateNow();
}
}