modify-line-flex-row.tentative.html (1964B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Selection.modify(): line navigation on a row-oriented flex container</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 7 <link rel="author" title="Mozilla" href="https://mozilla.org"> 8 <style> 9 p { display: flex } 10 </style> 11 <div id="container" style="font-family: monospace"> 12 <p><div></div><div id="one">One</div></p> 13 <p><div></div><div id="two">Two</div></p> 14 <p><div></div><div id="three">Three</div></p> 15 <p><div></div><div id="four">Four</div></p> 16 </div> 17 <script> 18 const selection = getSelection(); 19 test(() => { 20 // Put the caret in the second character in "One" 21 selection.collapse(one.childNodes[0], 2); 22 // Move forward a line, selection should be after "Tw". 23 selection.modify("extend", "forward", "line") 24 assert_equals(selection.focusNode, two.childNodes[0]); 25 assert_equals(selection.focusOffset, 2); 26 27 // Move forward another line, selection should be after "Th". 28 selection.modify("extend", "forward", "line") 29 assert_equals(selection.focusNode, three.childNodes[0]); 30 assert_equals(selection.focusOffset, 2); 31 32 assert_equals(selection.toString().replaceAll("\r\n", "\n"), "e\n\nTwo\n\nTh"); 33 }, "forward"); 34 35 test(() => { 36 // Put the caret in the second character in "Three" 37 selection.collapse(three.childNodes[0], 2); 38 // Move backward a line, selection should be after "Tw". 39 selection.modify("extend", "backward", "line") 40 assert_equals(selection.focusNode, two.childNodes[0]); 41 assert_equals(selection.focusOffset, 2); 42 43 // Move backward another line, selection should be after "On". 44 selection.modify("extend", "backward", "line") 45 assert_equals(selection.focusNode, one.childNodes[0]); 46 assert_equals(selection.focusOffset, 2); 47 48 assert_equals(selection.toString().replaceAll("\r\n", "\n"), "e\n\nTwo\n\nTh"); 49 }, "backward"); 50 </script>