Skip to content

Commit

Permalink
fix Incorrect childNodes.length after typing in an iframe (close De…
Browse files Browse the repository at this point in the history
  • Loading branch information
LavrovArtem authored and kirovboris committed Dec 18, 2019
1 parent 93f1bf6 commit 896438c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/client/core/utils/content-editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,8 @@ export function calculateNodeAndOffsetByPosition (el, offset) {
point.offset--;
}

arrayUtils.forEach(childNodes, node => {
point = checkChildNodes(node);
});
for (let i = 0; i < childNodesLength; i++)
point = checkChildNodes(childNodes[i]);

return point;
}
Expand Down Expand Up @@ -505,9 +504,8 @@ export function calculatePositionByNodeAndOffset (el, { node, offset }) {
else if (!find && (isNodeBlockWithBreakLine(el, target) || isNodeAfterNodeBlockWithBreakLine(el, target)))
currentOffset++;

arrayUtils.forEach(childNodes, currentNode => {
currentOffset = checkChildNodes(currentNode);
});
for (let i = 0; i < childNodesLength; i++)
currentOffset = checkChildNodes(childNodes[i]);

return currentOffset;
}
Expand Down Expand Up @@ -581,9 +579,8 @@ function getContentEditableNodes (target) {
if (!isSkippableNode(target) && !childNodesLength && domUtils.isTextNode(target))
result.push(target);

arrayUtils.forEach(childNodes, node => {
result = result.concat(getContentEditableNodes(node));
});
for (let i = 0; i < childNodesLength; i++)
result = result.concat(getContentEditableNodes(childNodes[i]));

return result;
}
Expand Down
18 changes: 18 additions & 0 deletions test/functional/fixtures/regression/gh-3887/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>GH-3887</title>
<script>
window.onload = function () {
var iframe = document.querySelector('iframe');
iframe.contentDocument.designMode = 'on';
iframe.contentDocument.body.innerHTML = 'a';
iframe.contentWindow.focus();
};
</script>
</head>
<body>
<iframe></iframe>
</body>
</html>
3 changes: 3 additions & 0 deletions test/functional/fixtures/regression/gh-3887/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('[Regression](GH-3887)', () => {
it('Should correctly return childNodes.length after typing in an iframe', () => runTests('testcafe-fixtures/index.js'));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fixture`gh-3887`
.page`http://localhost:3000/fixtures/regression/gh-3887/pages/index.html`;

test('Check body.childNodes.length after typing in an iframe', async t => {
await t
.switchToIframe('iframe')
.typeText('body', '=SU', { replace: true })
.typeText('body', '=SU', { replace: true })
.switchToMainWindow()
.pressKey('ctrl');

const count = await t.eval(() => document.querySelector('iframe').contentDocument.body.childNodes.length);

await t.expect(count).eql(1);
});

0 comments on commit 896438c

Please sign in to comment.