shortcutkeys.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. module( 'plugins.shortcutkeys' );
  2. //键盘操作取不到range,定不到位,尤其ie里ctrl+b把收藏夹打开了。。。
  3. test( 'ctrl+i', function() {
  4. var editor = te.obj[0];
  5. var range = te.obj[1];
  6. var body = editor.body;
  7. // setTimeout( function() {
  8. editor.setContent( '<p>没有加粗的文本</p>' );
  9. range.selectNode( body.firstChild ).select();
  10. var p = body.firstChild;
  11. editor.focus();
  12. setTimeout( function() {
  13. // te.presskey( 'ctrl', 'i' );
  14. ua.keydown(editor.body,{'keyCode':73,'ctrlKey':true});
  15. editor.focus();
  16. setTimeout( function() {
  17. equal( ua.getChildHTML( p ), '<em>没有加粗的文本</em>' );
  18. start();
  19. }, 150 );
  20. }, 100 );
  21. // }, 100 );
  22. stop();
  23. } );
  24. //
  25. test( 'ctrl+u', function() {
  26. var editor = te.obj[0];
  27. var range = te.obj[1];
  28. var body = editor.body;
  29. stop();
  30. editor.setContent( '<p>没有加粗的文本</p>' );
  31. setTimeout( function() {
  32. range.selectNode( body.firstChild ).select();
  33. var p = body.firstChild;
  34. editor.focus();
  35. // setTimeout( function() {
  36. // editor.focus();
  37. setTimeout( function() {
  38. var html = '<span style="text-decoration: underline">没有加粗的文本</span>';
  39. ua.checkHTMLSameStyle( html, editor.document, body.firstChild, '文本被添加了下划线' );
  40. start();
  41. }, 150 );
  42. // }, 100 );
  43. // te.presskey( 'ctrl', 'u' );
  44. ua.keydown(editor.body,{'keyCode':85,'ctrlKey':true});
  45. }, 150 );
  46. } );
  47. //
  48. test( 'ctrl+z/y', function() {
  49. var editor = te.obj[0];
  50. var range = te.obj[1];
  51. var body = editor.body;
  52. // setTimeout( function() {
  53. editor.setContent( '<p>没有加粗的文本</p>' );
  54. range.selectNode( body.firstChild ).select();
  55. var p = body.firstChild;
  56. editor.focus();
  57. setTimeout( function() {
  58. // te.presskey( 'ctrl', 'b' );
  59. // editor.focus();
  60. ua.keydown(editor.body,{'keyCode':66,'ctrlKey':true});
  61. setTimeout( function() {
  62. equal( ua.getChildHTML( p ), '<strong>没有加粗的文本</strong>' );
  63. // editor.focus();
  64. // te.presskey( 'ctrl', 'z' );
  65. ua.keydown(editor.body,{'keyCode':90,'ctrlKey':true});
  66. // editor.focus();
  67. setTimeout( function() {
  68. editor.focus();
  69. equal( ua.getChildHTML( body.firstChild ), '没有加粗的文本' );
  70. // setTimeout( function() {
  71. // te.presskey( 'ctrl', 'y' );
  72. ua.keydown(editor.body,{'keyCode':89,'ctrlKey':true});
  73. editor.focus();
  74. setTimeout( function() {
  75. // editor.focus();
  76. equal( ua.getChildHTML( body.firstChild ), '<strong>没有加粗的文本</strong>' );
  77. start();
  78. }, 100 );
  79. // }, 100 );
  80. }, 100 );
  81. }, 150 );
  82. }, 100 );
  83. // }, 150 );
  84. stop();
  85. } );
  86. //
  87. test( 'ctrl+a', function() {
  88. var editor = te.obj[0];
  89. var range = te.obj[1];
  90. var body = editor.body;
  91. // setTimeout( function() {
  92. editor.setContent( '<p>全选的文本1</p><h1>全选的文本2</h1>' );
  93. range.selectNode( body.firstChild ).select();
  94. var p = body.firstChild;
  95. ua.keydown(editor.body,{'keyCode':65,'ctrlKey':true});
  96. // setTimeout( function() {
  97. // editor.focus();
  98. // te.presskey( 'ctrl', 'a' );
  99. // editor.focus();
  100. setTimeout( function() {
  101. var range = editor.selection.getRange();
  102. if ( ua.browser.gecko )
  103. ua.checkResult( range, body, body, 0, 2, false, '查看全选后的range' );
  104. else
  105. ua.checkResult( range, body.firstChild.firstChild, body.lastChild.firstChild, 0, 6, false, '查看全选后的range' );
  106. start();
  107. }, 150 );
  108. // }, 100 );
  109. // }, 100 );
  110. stop();
  111. } );
  112. //
  113. test( 'ctrl+b', function() {
  114. var editor = te.obj[0];
  115. var range = te.obj[1];
  116. var body = editor.body;
  117. // setTimeout( function() {
  118. editor.setContent( '<p>没有加粗的文本</p>' );
  119. range.selectNode( body.firstChild ).select();
  120. editor.focus();
  121. setTimeout( function() {
  122. ua.keydown(editor.body,{'keyCode':66,'ctrlKey':true});
  123. // te.presskey( 'ctrl', 'b' );
  124. // editor.focus();
  125. setTimeout( function() {
  126. equal( ua.getChildHTML( body.firstChild ), '<strong>没有加粗的文本</strong>' );
  127. start();
  128. }, 150 );
  129. }, 150 );
  130. // } ,50);
  131. stop();
  132. } );