improve brFix logic

stop exporting functions which we wish to deprecate
pull/1/head
ansuz 9 years ago
parent 1c7954ed51
commit b83fb7b823

@ -27,8 +27,9 @@ define([
} }
}; };
// TODO deprecate
// assumes a negative index // assumes a negative index
var seekLeft = cursor.seekLeft = function (el, delta, current) { var seekLeft /* = cursor.seekLeft*/ = function (el, delta, current) {
var textLength; var textLength;
var previous; var previous;
@ -67,8 +68,9 @@ define([
}; };
}; };
// TODO deprecate
// seekRight assumes a positive delta // seekRight assumes a positive delta
var seekRight = cursor.seekRight = function (el, delta, current) { var seekRight = /* cursor.seekRight = */ function (el, delta, current) {
var textLength; var textLength;
var previous; var previous;
@ -107,7 +109,8 @@ define([
}; };
}; };
var seekToDelta = cursor.seekToDelta = function (el, delta, current) { // TODO deprecate
var seekToDelta = /* cursor.seekToDelta = */ function (el, delta, current) {
var result = null; var result = null;
if (el) { if (el) {
if (delta < 0) { if (delta < 0) {
@ -136,10 +139,9 @@ define([
verbose("cursor.update"); verbose("cursor.update");
root = root || inner; root = root || inner;
sel = sel || Rangy.getSelection(root); sel = sel || Rangy.getSelection(root);
if (!sel.rangeCount) {
error('[cursor.update] no ranges found'); // if the root element has no focus, there will be no range
return; if (!sel.rangeCount) { return; }
}
var range = sel.getRangeAt(0); var range = sel.getRangeAt(0);
// Big R Range is caught in closure, and maintains persistent state // Big R Range is caught in closure, and maintains persistent state
@ -149,19 +151,6 @@ define([
}); });
}; };
/* 0 -> neither is lost
1 -> start is lost
2 -> end is lost
3 -> both are lost */
/* sometimes the selection gets dropped and this doesn't realize it
figure out why (TODO FIXME) */
var isLost = cursor.isLost = function () {
var state = ['start', 'end'].map(function (pos, i) {
return Tree.contains(Range[pos].el, inner)? 0 : i + 1;
});
return state[0] | state[1];
};
var exists = cursor.exists = function () { var exists = cursor.exists = function () {
return (Range.start.el?1:0) | (Range.end.el?2:0); return (Range.start.el?1:0) | (Range.end.el?2:0);
}; };
@ -239,7 +228,8 @@ define([
} }
}; };
var pushDelta = cursor.pushDelta = function (oldVal, newVal, offset) { // TODO deprecate
var pushDelta = /* cursor.pushDelta =*/ function (oldVal, newVal, offset) {
if (oldVal === newVal) { return; } if (oldVal === newVal) { return; }
var commonStart = 0; var commonStart = 0;
while (oldVal.charAt(commonStart) === newVal.charAt(commonStart)) { while (oldVal.charAt(commonStart) === newVal.charAt(commonStart)) {
@ -274,6 +264,7 @@ define([
}; };
/* getLength assumes that both nodes exist inside of the active editor. */ /* getLength assumes that both nodes exist inside of the active editor. */
// unused currently
var getLength = cursor.getLength = function () { var getLength = cursor.getLength = function () {
if (Range.start.el === Range.end.el) { if (Range.start.el === Range.end.el) {
if (Range.start.offset === Range.end.offset) { return 0; } if (Range.start.offset === Range.end.offset) { return 0; }
@ -315,7 +306,9 @@ define([
} }
}; };
cursor.delta = function (delta1, delta2) { // previously used for testing
// TODO deprecate
var delta = /* cursor.delta = */ function (delta1, delta2) {
var sel = Rangy.getSelection(inner); var sel = Rangy.getSelection(inner);
delta2 = (typeof delta2 !== 'undefined') ? delta2 : delta1; delta2 = (typeof delta2 !== 'undefined') ? delta2 : delta1;
@ -381,8 +374,10 @@ define([
if (start.el === end.el && start.offset === end.offset) { if (start.el === end.el && start.offset === end.offset) {
if (start.el.tagName === 'BR') { if (start.el.tagName === 'BR') {
// get the parent element, which ought to be a P. var br = start.el;
var P = start.el.parentNode;
var P = (Tree.indexOfNode(br) === 0 ?
br.parentNode: br.previousSibling);
[cursor.fixStart, cursor.fixEnd].forEach(function (f) { [cursor.fixStart, cursor.fixEnd].forEach(function (f) {
f(P, 0); f(P, 0);

Loading…
Cancel
Save