|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>Selection.modify() character granularity in bidi text</title> |
| 4 | +<script src=/resources/testharness.js></script> |
| 5 | +<script src=/resources/testharnessreport.js></script> |
| 6 | + |
| 7 | +<style> |
| 8 | + #container div { font: 16px monospace; } |
| 9 | +</style> |
| 10 | + |
| 11 | +<div id="container"> |
| 12 | + <!-- [Hello World ] --> |
| 13 | + <div id="pure-ltr" dir="ltr">Hello World</div> |
| 14 | + <!-- [ مرحبا عالم] --> |
| 15 | + <div id="pure-rtl" dir="rtl">مرحبا عالم</div> |
| 16 | + <!-- [אבגדהו ] --> |
| 17 | + <div id="rtl-in-ltr" dir="ltr">אבגדהו</div> |
| 18 | + <!-- [ Hello World] --> |
| 19 | + <div id="ltr-in-rtl" dir="rtl">Hello World</div> |
| 20 | + <!-- [Hello אבגדהו World ] --> |
| 21 | + <div id="mixed-ltr" dir="ltr">Hello אבגדהו World</div> |
| 22 | + <!-- [ Hello World אבגדהו] --> |
| 23 | + <div id="mixed-auto" dir="auto">אבגדהו Hello World</div> |
| 24 | +</div> |
| 25 | + |
| 26 | +<script> |
| 27 | +const selection = getSelection(); |
| 28 | + |
| 29 | +function runTest(divId, count, direction, startOffset, endOffset, name) { |
| 30 | + test(() => { |
| 31 | + const div = document.getElementById(divId); |
| 32 | + selection.collapse(div.firstChild, startOffset); |
| 33 | + for (let i = 0; i < count; i++) { |
| 34 | + selection.modify("move", direction, "character"); |
| 35 | + } |
| 36 | + assert_equals(selection.focusOffset, endOffset); |
| 37 | + }, name); |
| 38 | +} |
| 39 | + |
| 40 | +// Move in logical direction forward/backward |
| 41 | + |
| 42 | +runTest("pure-ltr", 2, "forward", 3, 5, |
| 43 | + "LTR text in LTR paragraph: move forward 2 chars"); |
| 44 | +runTest("pure-ltr", 2, "backward", 5, 3, |
| 45 | + "LTR text in LTR paragraph: move backward 2 chars"); |
| 46 | + |
| 47 | +runTest("pure-rtl", 2, "forward", 2, 4, |
| 48 | + "RTL text in RTL paragraph: move forward 2 chars"); |
| 49 | +runTest("pure-rtl", 2, "backward", 4, 2, |
| 50 | + "RTL text in RTL paragraph: move backward 2 chars"); |
| 51 | + |
| 52 | +runTest("rtl-in-ltr", 2, "forward", 2, 4, |
| 53 | + "RTL text in LTR paragraph: move forward 2 chars"); |
| 54 | +runTest("rtl-in-ltr", 2, "backward", 4, 2, |
| 55 | + "RTL text in LTR paragraph: move backward 2 chars"); |
| 56 | + |
| 57 | +runTest("ltr-in-rtl", 2, "forward", 3, 5, |
| 58 | + "LTR text in RTL paragraph: move forward 2 chars"); |
| 59 | +runTest("ltr-in-rtl", 2, "backward", 5, 3, |
| 60 | + "LTR text in RTL paragraph: move backward 2 chars"); |
| 61 | + |
| 62 | +runTest("mixed-ltr", 3, "forward", 4, 7, |
| 63 | + "LTR-RTL context in LTR paragraph: move forward 3 chars"); |
| 64 | +runTest("mixed-ltr", 3, "backward", 11, 8, |
| 65 | + "LTR-RTL context in LTR paragraph: move backward 3 chars"); |
| 66 | +runTest("mixed-ltr", 3, "forward", 7, 10, |
| 67 | + "RTL-LTR context in LTR paragraph: move forward 3 chars"); |
| 68 | +runTest("mixed-ltr", 3, "backward", 14, 11, |
| 69 | + "RTL-LTR context in LTR paragraph: move backward 3 chars"); |
| 70 | + |
| 71 | +runTest("mixed-auto", 3, "forward", 5, 8, |
| 72 | + "Mixed context in auto-dir paragraph: move forward 3 chars"); |
| 73 | +runTest("mixed-auto", 3, "backward", 17, 14, |
| 74 | + "Mixed context in auto-dir paragraph: move backward 3 chars"); |
| 75 | + |
| 76 | +// Move in true visual direction left/right |
| 77 | + |
| 78 | +runTest("pure-ltr", 2, "right", 3, 5, |
| 79 | + "LTR text in LTR paragraph: move right 2 chars"); |
| 80 | +runTest("pure-ltr", 2, "left", 5, 3, |
| 81 | + "LTR text in LTR paragraph: move left 2 chars"); |
| 82 | + |
| 83 | +runTest("pure-rtl", 2, "right", 4, 2, |
| 84 | + "RTL text in RTL paragraph: move right 2 chars"); |
| 85 | +runTest("pure-rtl", 2, "left", 2, 4, |
| 86 | + "RTL text in RTL paragraph: move left 2 chars"); |
| 87 | + |
| 88 | +runTest("rtl-in-ltr", 2, "right", 4, 2, |
| 89 | + "RTL text in LTR paragraph: move right 2 chars"); |
| 90 | +runTest("rtl-in-ltr", 2, "left", 2, 4, |
| 91 | + "RTL text in LTR paragraph: move left 2 chars"); |
| 92 | + |
| 93 | +runTest("ltr-in-rtl", 2, "right", 3, 5, |
| 94 | + "LTR text in RTL paragraph: move right 2 chars"); |
| 95 | +runTest("ltr-in-rtl", 2, "left", 5, 3, |
| 96 | + "LTR text in RTL paragraph: move left 2 chars"); |
| 97 | + |
| 98 | +runTest("mixed-ltr", 3, "right", 4, 11, |
| 99 | + "LTR-RTL context in LTR paragraph: move right 3 chars"); |
| 100 | +runTest("mixed-ltr", 3, "left", 11, 4, |
| 101 | + "LTR-RTL context in LTR paragraph: move left 3 chars"); |
| 102 | +runTest("mixed-ltr", 3, "right", 7, 14, |
| 103 | + "RTL-LTR context in LTR paragraph: move right 3 chars"); |
| 104 | +runTest("mixed-ltr", 3, "left", 14, 7, |
| 105 | + "RTL-LTR context in LTR paragraph: move left 3 chars"); |
| 106 | + |
| 107 | +runTest("mixed-auto", 3, "right", 17, 5, |
| 108 | + "Mixed context in auto-dir paragraph: move right 3 chars"); |
| 109 | +runTest("mixed-auto", 3, "left", 5, 17, |
| 110 | + "Mixed context in auto-dir paragraph: move left 3 chars"); |
| 111 | + |
| 112 | +</script> |
0 commit comments