| <html> |
| <head> |
| <script src="../../../resources/js-test.js"></script> |
| </head> |
| <body> |
| <p>This tests for problems where we'd lose the selection in a textarea when making style and value changes.</p> |
| <div id="console"></div> |
| <form id="form"><textarea id="ta">abc123 |
| </textarea></form> |
| <script type="text/javascript"> |
| var ta = document.getElementById('ta'); |
| debug("- default value"); |
| shouldBe('ta.selectionStart', '0'); |
| shouldBe('ta.selectionEnd', '0'); |
| debug("- set selectionStart/End"); |
| ta.selectionStart = 3; |
| ta.selectionEnd = 4; |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| debug("- add background style"); |
| ta.setAttribute("style", "background-color: yellow"); |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| debug("- set value to same value"); |
| ta.value = "abc123\n"; |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| debug("- set value to a different value"); |
| ta.value = "abc123"; |
| shouldBe('ta.selectionStart', '6'); |
| shouldBe('ta.selectionEnd', '6'); |
| debug("- set selection so we can test again without a trailing newline"); |
| ta.selectionStart = 3; |
| ta.selectionEnd = 4; |
| ta.removeAttribute("style"); |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| debug("- add background style"); |
| ta.setAttribute("style", "background-color: yellow"); |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| debug("- set value to same value"); |
| ta.value = "abc123"; |
| shouldBe('ta.selectionStart', '3'); |
| shouldBe('ta.selectionEnd', '4'); |
| |
| debug("- reset form"); |
| form.reset(); |
| shouldBe('ta.selectionStart', '7'); |
| shouldBe('ta.selectionEnd', '7'); |
| |
| debug("- append a empty text node"); |
| ta.setSelectionRange(2, 3); |
| ta.appendChild(document.createTextNode('')); |
| shouldBe('ta.selectionStart', '2'); |
| shouldBe('ta.selectionEnd', '3'); |
| </script> |
| </body> |
| </html> |