File: editable-scroll-anchor.html

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (72 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<meta charset="utf-8">
<title>Scroll anchoring is suppressed during editing in editable elements</title>
<link rel="author" href="mailto:zhoupeng.1996@bytedance.com">
<link rel="help" href="https://drafts.csswg.org/css-scroll-anchoring-1/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/dom/events/scrolling/scroll_support.js"></script>
<script src="/css/css-scroll-snap/support/common.js"></script>
<style>
textarea,
div {
  font-size: 14px;
  width: 685px;
  height: 716px;
}
</style>
<body>
<script>
const baseText = 'Scroll Anchor Test of the editable element.';
const text = Array(500).fill(baseText).join(' ');
const caretOffset = 426;
const targetScrollTop = 30;

// Perform an editing operation while scroll anchoring is suppressed.
async function insertLineBreak(element) {
  let scrollEndPromise = waitForScrollEndOrTimeout(element, 1000);
  element.scrollTop = targetScrollTop;
  await scrollEndPromise;
  assert_equals(element.scrollTop, targetScrollTop);
  scrollEndPromise = waitForScrollEndOrTimeout(element, 1000);
  document.execCommand('insertLineBreak');
  await scrollEndPromise;
  assert_equals(element.scrollTop, targetScrollTop);
}

promise_test(async t => {
  const textarea = document.createElement('textarea');
  textarea.value = text;
  document.body.appendChild(textarea);

  textarea.focus();
  textarea.setSelectionRange(caretOffset, caretOffset);
  assert_equals(textarea.selectionStart, caretOffset);
  assert_equals(textarea.selectionEnd, caretOffset);

  await insertLineBreak(textarea);
  textarea.remove();
}, 'Scroll anchoring is suppressed during editing in a textarea');

promise_test(async t => {
  const selection = window.getSelection();
  const editable = document.createElement('div');
  editable.contentEditable = true;
  editable.innerText = text;
  document.body.appendChild(editable);

  editable.focus();
  const range = document.createRange();
  const textNode = editable.firstChild;
  assert_equals(textNode.nodeType, Node.TEXT_NODE);
  range.setStart(textNode, caretOffset);
  range.collapse(true);
  selection.removeAllRanges();
  selection.addRange(range);
  assert_equals(selection.anchorOffset, caretOffset);

  await insertLineBreak(document.documentElement);
  editable.remove();
}, 'Scroll anchoring is suppressed during editing in a contenteditable element');
</script>
</body>