Fix cursor recovery in pad

pull/1/head
yflory 5 years ago
parent 97f41edd94
commit 0a72ed2977

@ -3,7 +3,7 @@ define([], function () {
var indexOfNode = tree.indexOfNode = function (el) { var indexOfNode = tree.indexOfNode = function (el) {
if (!(el && el.parentNode)) { if (!(el && el.parentNode)) {
console.log("No parentNode found!"); console.log("No parentNode found!", el);
throw new Error('No parentNode found!'); throw new Error('No parentNode found!');
} }
return Array.prototype.indexOf.call(el.parentNode.childNodes, el); return Array.prototype.indexOf.call(el.parentNode.childNodes, el);
@ -26,6 +26,7 @@ define([], function () {
leaf nodes of a tree leaf nodes of a tree
*/ */
var rightmostNode = tree.rightmostNode = function (el) { var rightmostNode = tree.rightmostNode = function (el) {
if (!el) { return null; }
var childNodeCount = childCount(el); var childNodeCount = childCount(el);
if (!childNodeCount) { // no children if (!childNodeCount) { // no children
return el; // return the element return el; // return the element
@ -53,7 +54,7 @@ define([], function () {
if (!el.parentNode) { return null; } if (!el.parentNode) { return null; }
if (i === 0) { if (i === 0) {
if (root && el.parentNode === root.childNodes[0]) { return null; } if (root && el.parentNode === root.childNodes[0]) { return null; }
return rightmostNode(previousNode(el.parentNode)); return rightmostNode(previousNode(el.parentNode, root));
} else { } else {
return rightmostNode(el.parentNode.childNodes[i-1]); return rightmostNode(el.parentNode.childNodes[i-1]);
} }
@ -77,6 +78,10 @@ define([], function () {
// a and b might be the same element // a and b might be the same element
if (a === b) { return 0; } if (a === b) { return 0; }
// If we're selecting an entire node containing a single text node,
// b can be the child of a. Order is correct.
if (b.parentNode && b.parentNode === a) { return 1; }
var cur = b; var cur = b;
while (cur) { while (cur) {
cur = previousNode(cur, root); cur = previousNode(cur, root);

Loading…
Cancel
Save