diff --git a/src/client/core/utils/content-editable.js b/src/client/core/utils/content-editable.js index 46dfb13bd9..4546fa4797 100644 --- a/src/client/core/utils/content-editable.js +++ b/src/client/core/utils/content-editable.js @@ -285,16 +285,16 @@ export function getNearestCommonAncestor (node1, node2) { //selection utils function getSelectedPositionInParentByOffset (node, offset) { - // NOTE: we get a child element by its offset index in the parent - if (domUtils.isShadowUIElement(node)) - return { node, offset }; - const childNodes = nativeMethods.nodeChildNodesGetter.call(node); const childCount = domUtils.getChildNodesLength(childNodes); let isSearchForLastChild = offset >= childCount; let currentNode = childNodes[offset]; let currentOffset = 0; + // NOTE: we get a child element by its offset index in the parent + if (domUtils.isShadowUIElement(node) || !currentNode) + return { node, offset }; + // NOTE: skip shadowUI elements if (domUtils.isShadowUIElement(currentNode)) { if (childCount <= 1) diff --git a/test/functional/fixtures/regression/gh-8321/pages/index.html b/test/functional/fixtures/regression/gh-8321/pages/index.html new file mode 100644 index 0000000000..4a6a85f03e --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/pages/index.html @@ -0,0 +1,23 @@ + + + + + + +
+
example
+
+ + + \ No newline at end of file diff --git a/test/functional/fixtures/regression/gh-8321/test.js b/test/functional/fixtures/regression/gh-8321/test.js new file mode 100644 index 0000000000..b0c7fe6211 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/test.js @@ -0,0 +1,5 @@ +describe('[Regression](GH-8321)', function () { + it('Should type text without errors when document selection is updated', function () { + return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' }); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js b/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js new file mode 100644 index 0000000000..3bdfcc048e --- /dev/null +++ b/test/functional/fixtures/regression/gh-8321/testcafe-fixtures/index.js @@ -0,0 +1,11 @@ +import { Selector } from 'testcafe'; + +fixture('GH-8321 - Callsite Issue') + .page`http://localhost:3000/fixtures/regression/gh-8321/pages/index.html`; + +test('Callsite Issue', async t => { + const editor = Selector('[contenteditable=true]'); + + await t.click(editor); + await t.typeText(editor, 'text1'); +});