We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Point
isBefore
Reported internally by @olegbl:
As far as I can tell, the calculation inside Point.isBefore is not quite right when comparing an Element Point to a Text Point: if ($isElementNode(aNode)) { const aNodeDescendant = aNode.getDescendantByIndex(aOffset); aNode = aNodeDescendant != null ? aNodeDescendant : aNode; } changes the value of aNode but does not change aOffset. As a result, when it gets used down below in if (aNode === bNode) { return aOffset < bOffset; } The aOffset is being applied twice and leads to an incorrect result. e.g.: // nodes 1 (element node) 2 (text node) 3 (element node) 4 (text node) 5 (text node) <-- point1 is here 6 (text node) <-- point2 is inside here 7 (text node) // point1 key = 3 offset = 2 // point2 key = 6 offset = 1 // test: point1.isBefore(point2) // this should be true // aNode = node 3 // aOffset = 2 // bNode = node 6 // bOffset = 1 if ($isElementNode(aNode)) { const aNodeDescendant = aNode.getDescendantByIndex(aOffset); aNode = aNodeDescendant != null ? aNodeDescendant : aNode; } // aNode = node 6 if (aNode === bNode) { // true return aOffset < bOffset; // 2 < 1 = false (this is wrong) }
As far as I can tell, the calculation inside Point.isBefore is not quite right when comparing an Element Point to a Text Point:
Point.isBefore
if ($isElementNode(aNode)) { const aNodeDescendant = aNode.getDescendantByIndex(aOffset); aNode = aNodeDescendant != null ? aNodeDescendant : aNode; }
changes the value of aNode but does not change aOffset. As a result, when it gets used down below in
if (aNode === bNode) { return aOffset < bOffset; }
The aOffset is being applied twice and leads to an incorrect result. e.g.:
// nodes 1 (element node) 2 (text node) 3 (element node) 4 (text node) 5 (text node) <-- point1 is here 6 (text node) <-- point2 is inside here 7 (text node) // point1 key = 3 offset = 2 // point2 key = 6 offset = 1 // test: point1.isBefore(point2) // this should be true // aNode = node 3 // aOffset = 2 // bNode = node 6 // bOffset = 1 if ($isElementNode(aNode)) { const aNodeDescendant = aNode.getDescendantByIndex(aOffset); aNode = aNodeDescendant != null ? aNodeDescendant : aNode; } // aNode = node 6 if (aNode === bNode) { // true return aOffset < bOffset; // 2 < 1 = false (this is wrong) }
The text was updated successfully, but these errors were encountered:
fix is before when there is offset in element
b5f5528
facebook#3181
09aae52
zurfyx
Successfully merging a pull request may close this issue.
Reported internally by @olegbl:
The text was updated successfully, but these errors were encountered: