Skip to content
New issue

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

fix: typetext issue test #8342

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/client/core/utils/content-editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions test/functional/fixtures/regression/gh-8321/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div contenteditable="true">
<div id="myText">example</div>
</div>
</body>
<script>
const element = document.getElementById("myText");
element.addEventListener("click", () => {
const selection = document.getSelection();
const range = document.createRange();

range.selectNodeContents(element);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
});
</script>
</html>
5 changes: 5 additions & 0 deletions test/functional/fixtures/regression/gh-8321/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('[Regression](GH-8321)', function () {
it('Test should not fail with Uncaught object error on typeText', function () {
return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' });
});
});
Original file line number Diff line number Diff line change
@@ -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');
});
Loading