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 @@ + + +
+ + + +