Skip to content

Commit

Permalink
Bug fix traversing using walkPoint() and nextPointWithEmptyNode()
Browse files Browse the repository at this point in the history
Previously algorithm would eject early if it encountered an empty child node, and the next sibling was empty as well.
Modelled the method on nextPoint, which had similar fixes to pasteHTML()
  • Loading branch information
Duncan Houston committed May 17, 2023
1 parent 9b33ce6 commit a708fd1
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions src/js/core/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ function nextPoint(point, isSkipInnerOffset) {
}

/**
* Find next boundaryPoint for preorder / depth first traversal of the DOM
* returns next boundaryPoint with empty node
*
* @param {BoundaryPoint} point
Expand All @@ -612,21 +613,6 @@ function nextPoint(point, isSkipInnerOffset) {
function nextPointWithEmptyNode(point, isSkipInnerOffset) {
let node, offset = 0;

// if node is empty string node, return current node's sibling.
if (isEmpty(point.node)) {
if(point.node === null){
return null;
}

node = point.node.nextSibling;
offset = 0;

return {
node: node,
offset: offset,
};
}

if (nodeLength(point.node) === point.offset) {
if (isEditable(point.node)) {
return null;
Expand All @@ -635,31 +621,17 @@ function nextPointWithEmptyNode(point, isSkipInnerOffset) {
node = point.node.parentNode;
offset = position(point.node) + 1;

// if next node is editable , return current node's sibling node.
// if parent node is editable, return current node's sibling node.
if (isEditable(node)) {
node = point.node.nextSibling;
offset = 0;
}

} else if (hasChildren(point.node)) {
node = point.node.childNodes[point.offset];
offset = 0;
if (isEmpty(node)) {
if (!isEmpty(point.node.nextSibling)) {
return {
node: point.node.nextSibling,
offset: offset,
};
}
return null;
}
} else {
node = point.node;
offset = isSkipInnerOffset ? nodeLength(point.node) : point.offset + 1;

if (isEmpty(node)) {
return null;
}
}

return {
Expand Down Expand Up @@ -779,7 +751,7 @@ function isSpacePoint(point) {
}

/**
* @method walkPoint
* @method walkPoint - preorder / depth first traversal of the DOM
*
* @param {BoundaryPoint} startPoint
* @param {BoundaryPoint} endPoint
Expand Down

0 comments on commit a708fd1

Please sign in to comment.