Merge branch 'cursor' into staging
This commit is contained in:
@@ -173,7 +173,12 @@ define([
|
||||
// their length.
|
||||
var newOffset = offset;
|
||||
for (var i = 0; i < el.childNodes.length; i++) {
|
||||
try {
|
||||
newOffset -= (getTextNodeValue(el.childNodes[i]) || el.childNodes[i].outerHTML).length;
|
||||
} catch (e) {
|
||||
console.log(el);
|
||||
console.log(el.childNodes[i]);
|
||||
}
|
||||
if (newOffset <= 0) {
|
||||
return getFinalRange(el.childNodes[i], offset);
|
||||
}
|
||||
@@ -216,6 +221,19 @@ define([
|
||||
return range;
|
||||
};
|
||||
|
||||
cursor.getNewOffset = function (ops) {
|
||||
return {
|
||||
selectionStart: offsetTransformRange(offsetRange.start, ops),
|
||||
selectionEnd: offsetTransformRange(offsetRange.end, ops)
|
||||
};
|
||||
};
|
||||
cursor.getNewRange = function (data, ops) {
|
||||
offsetRange.start = offsetTransformRange(data.start, ops);
|
||||
offsetRange.end = offsetTransformRange(data.end, ops);
|
||||
var range = getRangeFromOffset(inner);
|
||||
return range;
|
||||
};
|
||||
|
||||
// Restore the cursor position after applying the changes.
|
||||
cursor.restoreOffset = function (ops) {
|
||||
try {
|
||||
|
||||
@@ -332,7 +332,11 @@ define([
|
||||
if (!readOnly && cursorGetter) {
|
||||
common.openCursorChannel(onLocal);
|
||||
cursor = common.createCursor();
|
||||
cursor.onCursorUpdate(evCursorUpdate.fire);
|
||||
cursor.onCursorUpdate(function (data) {
|
||||
var newContentStr = cpNfInner.chainpad.getUserDoc();
|
||||
var hjson = normalize(JSON.parse(newContentStr));
|
||||
evCursorUpdate.fire(data, hjson);
|
||||
});
|
||||
}
|
||||
|
||||
UI.removeLoadingScreen(emitResize);
|
||||
@@ -654,7 +658,9 @@ define([
|
||||
onCursorUpdate: evCursorUpdate.reg,
|
||||
updateCursor: function () {
|
||||
if (cursor && cursorGetter) {
|
||||
cursor.updateCursor(cursorGetter());
|
||||
var newContentStr = cpNfInner.chainpad.getUserDoc();
|
||||
var data = normalize(JSON.parse(newContentStr));
|
||||
cursor.updateCursor(cursorGetter(data));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user