File: modify-around-non-editable-span.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (116 lines) | stat: -rw-r--r-- 5,795 bytes parent folder | download | duplicates (11)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Selection.modify() shouldn't move caret into non-editable nodes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../editing/include/editor-test-utils.js"></script>
<script>
"use strict";

addEventListener("load", () => {
  const editingHost = document.querySelector("div[contenteditable]");
  editingHost.focus();
  const precedingWhiteSpaces = editingHost.firstChild;
  const middleText = editingHost.querySelector("span").nextSibling;
  const trailingWhiteSpaces = editingHost.lastChild;
  for (const callSelectAllChildren of [false, true]) {
    for (const direction of ["forward", "right"]) {
      test(() => {
        if (callSelectAllChildren) {
          getSelection().selectAllChildren(editingHost);
        }
        getSelection().collapse(precedingWhiteSpaces, precedingWhiteSpaces.length);
        getSelection().modify("move", direction, "character");
        assert_in_array(
          EditorTestUtils.getRangeDescription(getSelection().getRangeAt(0)),
          [
            // start of editable region at middle of the line
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 2, endContainer: editingHost, endOffset: 2 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: middleText, startOffset: 0, endContainer: middleText, endOffset: 0 }),
          ]
        );
      }, `getSelection().modify("move", "${direction}", "character") ${
        callSelectAllChildren ? "after getSelection().selectAllChildren(editingHost) " : ""
      }when " []<span contenteditable=false>"`);
      test(() => {
        if (callSelectAllChildren) {
          getSelection().selectAllChildren(editingHost);
        }
        getSelection().collapse(middleText, middleText.length);
        getSelection().modify("move", direction, "character");
        assert_in_array(
          EditorTestUtils.getRangeDescription(getSelection().getRangeAt(0)),
          [
            // At start of trailing invisible white spaces
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 4, endContainer: editingHost, endOffset: 4 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: trailingWhiteSpaces, startOffset: 0, endContainer: trailingWhiteSpaces, endOffset: 0 }),
            // or at end of trailing invisible white spaces
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 5, endContainer: editingHost, endOffset: 5 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: trailingWhiteSpaces, startOffset: trailingWhiteSpaces.length, endContainer: trailingWhiteSpaces, endOffset: trailingWhiteSpaces.length }),
          ]
        );
      }, `getSelection().modify("move", "${direction}", "character") ${
        callSelectAllChildren ? "after getSelection().selectAllChildren(editingHost) " : ""
      }when "editable[]<span contenteditable=false>"`);
    }
    for (const direction of ["backward", "left"]) {
      test(() => {
        if (callSelectAllChildren) {
          getSelection().selectAllChildren(editingHost);
        }
        getSelection().collapse(middleText, 0);
        getSelection().modify("move", direction, "character");
        assert_in_array(
          EditorTestUtils.getRangeDescription(getSelection().getRangeAt(0)),
          [
            // At end of preceding invisible white spaces
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 1, endContainer: editingHost, endOffset: 1 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: precedingWhiteSpaces, startOffset: 1, endContainer: precedingWhiteSpaces, endOffset: 1 }),
            // or start of preceding invisible whites spaces
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 0, endContainer: editingHost, endOffset: 0 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: precedingWhiteSpaces, startOffset: 0, endContainer: precedingWhiteSpaces, endOffset: 0 }),
          ]
        );
      }, `getSelection().modify("move", "${direction}", "character") ${
        callSelectAllChildren ? "after getSelection().selectAllChildren(editingHost) " : ""
      }when " <span contenteditable=false>...</span>[]editable"`);
      test(() => {
        if (callSelectAllChildren) {
          getSelection().selectAllChildren(editingHost);
        }
        getSelection().collapse(trailingWhiteSpaces, 0);
        getSelection().modify("move", direction, "character");
        assert_in_array(
          EditorTestUtils.getRangeDescription(getSelection().getRangeAt(0)),
          [
            // end of editable region at middle of the line
            EditorTestUtils.getRangeDescription(
              { startContainer: editingHost, startOffset: 3, endContainer: editingHost, endOffset: 3 }),
            EditorTestUtils.getRangeDescription(
              { startContainer: middleText, startOffset: middleText.length, endContainer: middleText, endOffset: middleText.length }),
          ]
        );
      }, `getSelection().modify("move", "${direction}", "character") ${
        callSelectAllChildren ? "after getSelection().selectAllChildren(editingHost) " : ""
      }when "editable<span contenteditable=false>...</span>[] "`);
    }
  }
}, {once: true});
</script>
</head>
<body>
<div contenteditable> <span contenteditable="false">non-editable</span>editable<span contenteditable="false">non-editable</span> </div>
</body>
</html>