bug585922.html (1266B)
1 <!DOCTYPE html> 2 <html class="reftest-wait"> 3 <head> 4 <script src="/tests/SimpleTest/EventUtils.js"></script> 5 </head> 6 <body onload="doTest()"> 7 <input type=text style="-moz-appearance: none"> 8 <script> 9 function doTest() { 10 function enableCaret(aEnable) { 11 var selCon = editor.selectionController; 12 selCon.setCaretEnabled(aEnable); 13 } 14 15 var d = document.querySelector("input"); 16 d.value = "a"; 17 d.focus(); 18 var editor = SpecialPowers.wrap(d).editor; 19 var sel = editor.selection; 20 var t = editor.rootElement.firstChild; 21 sel.collapse(t, 1); // put the caret at the end of the div 22 setTimeout(function() { 23 enableCaret(false);enableCaret(true);// force a caret display 24 enableCaret(false); // hide the caret 25 t.replaceData(0, 1, "b"); // replace the text node data 26 // at this point, the selection is collapsed to offset 0 27 synthesizeQuerySelectedText(); // call nsCaret::GetGeometry 28 sel.collapse(t, 1); // put the caret at the end again 29 enableCaret(true); // show the caret again 30 document.documentElement.removeAttribute("class"); 31 }, 0); 32 } 33 </script> 34 </body> 35 </html>