Skip to content

Commit cc0f2f8

Browse files
BayheckBayheck
andauthored
fix: typetext issue test (#8342)
<!-- Thank you for your contribution. Before making a PR, please read our contributing guidelines at https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution We recommend creating a *draft* PR, so that you can mark it as 'ready for review' when you are done. --> ## Purpose _Describe the problem you want to address or the feature you want to implement._ ## Approach _Describe how your changes address the issue or implement the desired functionality in as much detail as possible._ ## References closes #8321 ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail --------- Co-authored-by: Bayheck <[email protected]>
1 parent 817e3a4 commit cc0f2f8

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/client/core/utils/content-editable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@ export function getNearestCommonAncestor (node1, node2) {
285285

286286
//selection utils
287287
function getSelectedPositionInParentByOffset (node, offset) {
288-
// NOTE: we get a child element by its offset index in the parent
289-
if (domUtils.isShadowUIElement(node))
290-
return { node, offset };
291-
292288
const childNodes = nativeMethods.nodeChildNodesGetter.call(node);
293289
const childCount = domUtils.getChildNodesLength(childNodes);
294290
let isSearchForLastChild = offset >= childCount;
295291
let currentNode = childNodes[offset];
296292
let currentOffset = 0;
297293

294+
// NOTE: we get a child element by its offset index in the parent
295+
if (domUtils.isShadowUIElement(node) || !currentNode)
296+
return { node, offset };
297+
298298
// NOTE: skip shadowUI elements
299299
if (domUtils.isShadowUIElement(currentNode)) {
300300
if (childCount <= 1)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
</head>
6+
<body>
7+
<div contenteditable="true">
8+
<div id="myText">example</div>
9+
</div>
10+
</body>
11+
<script>
12+
const element = document.getElementById("myText");
13+
element.addEventListener("click", () => {
14+
const selection = document.getSelection();
15+
const range = document.createRange();
16+
17+
range.selectNodeContents(element);
18+
range.collapse(false);
19+
selection.removeAllRanges();
20+
selection.addRange(range);
21+
});
22+
</script>
23+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('[Regression](GH-8321)', function () {
2+
it('Should type text without errors when document selection is updated', function () {
3+
return runTests('testcafe-fixtures/index.js', 'Callsite Issue', { only: 'chrome' });
4+
});
5+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Selector } from 'testcafe';
2+
3+
fixture('GH-8321 - Callsite Issue')
4+
.page`http://localhost:3000/fixtures/regression/gh-8321/pages/index.html`;
5+
6+
test('Callsite Issue', async t => {
7+
const editor = Selector('[contenteditable=true]');
8+
9+
await t.click(editor);
10+
await t.typeText(editor, 'text1');
11+
});

0 commit comments

Comments
 (0)