undo.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. module("plugins.undo");
  2. //test('', function () {
  3. // stop()
  4. //});
  5. /*trace 856*/
  6. test('trace 856 输入文本后撤销按钮不亮', function () {
  7. var editor = te.obj[0];
  8. var range = te.obj[1];
  9. editor.setContent('<p></p>');
  10. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  11. ua.keydown(editor.body);
  12. range.insertNode(editor.document.createTextNode('hello'));
  13. ua.keydown(editor.body);
  14. setTimeout(function () {
  15. equal(editor.queryCommandState('undo'), 0, '模拟输入文本后撤销按钮应当高亮');
  16. start();
  17. }, 500);
  18. stop();
  19. });
  20. /*trace 583,1726*/
  21. test('trace 583,1726 插入表格、表情,撤销', function () {
  22. var editor = te.obj[0];
  23. var range = te.obj[1];
  24. editor.setContent('<p></p>');
  25. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  26. editor.execCommand('inserttable', {numCols: 2, numRows: 2});
  27. editor.execCommand('insertimage', {src: 'http://img.baidu.com/hi/jx2/j_0001.gif', width: 50, height: 50});
  28. editor.execCommand('undo');
  29. editor.execCommand('undo');
  30. editor.execCommand('undo');//需要3次undo,已经和RD确认过,暂时不改
  31. ua.manualDeleteFillData(editor.body);
  32. equal(editor.getContent().toLowerCase(), '', '插入表格、表情,撤销');
  33. });
  34. /*trace 595*/
  35. test('trace 595 撤销合并单元格后再合并单元格', function () {
  36. var editor = te.obj[0];
  37. var range = te.obj[1];
  38. editor.setContent('<p></p>');
  39. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  40. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  41. var tds = editor.body.firstChild.getElementsByTagName('td');
  42. for (var i = 0; i < 5; i++) {
  43. tds[i].innerHTML = 'hello';
  44. }
  45. //合并单元格
  46. setTimeout(function () {
  47. var trs = editor.body.firstChild.getElementsByTagName('tr');
  48. var ut = editor.getUETable(editor.body.firstChild);
  49. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  50. ut.setSelected(cellsRange);
  51. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  52. editor.execCommand('mergecells');
  53. ua.manualDeleteFillData(editor.body);
  54. var tds = editor.body.getElementsByTagName('td');
  55. equal(tds.length, 6, '单元格数');
  56. equal(trs[0].cells[0].colSpan, 2, '合并--[0][0]单元格colspan');
  57. equal(trs[0].cells[0].rowSpan, 2, '合并--[0][0]单元格rowspan');
  58. equal(trs[0].cells[0].innerHTML.toLowerCase(), 'hello<br>hello<br>hello<br>hello', '内容复制正确');
  59. //撤销合并单元格的操作
  60. editor.execCommand('undo');
  61. ua.manualDeleteFillData(editor.body);
  62. ok(tds[0].colSpan == 1 && tds[0].rowSpan == 1 && tds.length == 9, '撤销后,单元格回复成多个');
  63. ok(tds[0].innerHTML.toLowerCase() == 'hello' && tds[1].innerHTML.toLowerCase() == 'hello' && tds[3].innerHTML.toLowerCase() == 'hello' && tds[4].innerHTML.toLowerCase() == 'hello', '内容复制正确');
  64. //再次合并单元格
  65. setTimeout(function () {
  66. var trs = editor.body.firstChild.getElementsByTagName('tr');
  67. var ut = editor.getUETable(editor.body.firstChild);
  68. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  69. ut.setSelected(cellsRange);
  70. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  71. editor.execCommand('mergecells');
  72. ua.manualDeleteFillData(editor.body);
  73. tds = editor.body.firstChild.getElementsByTagName('td');
  74. ok(tds[0].colSpan == 2 && tds[0].rowSpan == 2 && tds.length == 6, '再次合并,多个单元格合并成一个');
  75. equal(tds[0].innerHTML.toLowerCase(), 'hello<br>hello<br>hello<br>hello', '内容复制正确');
  76. start();
  77. }, 50);
  78. }, 50);
  79. stop();
  80. });
  81. /*trace 599*/
  82. test('trace 599 插入表格、表情、超链接、表情,撤销2次', function () {
  83. var editor = te.obj[0];
  84. var range = te.obj[1];
  85. editor.setContent('<p></p>');
  86. range.setStart(editor.body, 0).collapse(true).select();
  87. editor.execCommand('inserttable', {numCols: 2, numRows: 2}); //插入表格
  88. range.setStart(editor.body.lastChild, 0).collapse(true).select();
  89. editor.execCommand('insertimage', {src: 'http://img.baidu.com/hi/jx2/j_0001.gif', width: 50, height: 50}); //插入表情
  90. range.setStartAfter(editor.body.lastChild).collapse(true).select();
  91. editor.execCommand('link', {href: 'http://www.baidu.com/'}); //插入超链接
  92. range.setStartAfter(editor.body.lastChild).collapse(true).select();
  93. editor.execCommand('insertimage', {src: 'http://img.baidu.com/hi/jx2/j_0001.gif', width: 50, height: 50}); //插入表情
  94. editor.execCommand('Undo');
  95. editor.execCommand('Undo');
  96. ua.manualDeleteFillData(editor.body);
  97. equal(editor.body.childNodes.length, 2, '撤销2次后只剩表格、表情');
  98. var tag = editor.body.childNodes[0].firstChild.tagName.toLowerCase();
  99. ok(tag == 'table' || tag == 'tbody', '表格');
  100. equal(editor.body.childNodes[1].firstChild.tagName.toLowerCase(), 'img', '表情');
  101. });
  102. /*trace 617*/
  103. test('trace 617 插入文本、分割线、文本,撤销2次,撤销掉分割线', function () {
  104. var editor = te.obj[0];
  105. var range = te.obj[1];
  106. editor.setContent('<p></p>');
  107. //输入文本
  108. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  109. ua.keydown(editor.body);
  110. range.insertNode(editor.document.createTextNode('hello'));
  111. if (!ua.browser.ie)
  112. ua.compositionstart(editor.body);
  113. ua.keyup(editor.body);
  114. //输入分割符
  115. range.setStartAfter(editor.body.lastChild).collapse(true).select();
  116. editor.execCommand('Horizontal');
  117. //输入文本
  118. range.setStartAfter(editor.body.lastChild).collapse(true).select();
  119. ua.keydown(editor.body);
  120. range.insertNode(editor.document.createTextNode('hello'));
  121. if (!ua.browser.ie)
  122. ua.compositionend(editor.body);
  123. ua.keyup(editor.body);
  124. editor.execCommand('Undo');
  125. editor.execCommand('Undo');
  126. equal(editor.body.getElementsByTagName('hr').length, 0, '分割线已删除');
  127. });
  128. /*trace 632*/
  129. test('trace 632 合并单元格后撤销再合并单元格不会丢字', function () {
  130. var editor = te.obj[0];
  131. var range = te.obj[1];
  132. editor.setContent('<p></p>');
  133. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  134. editor.execCommand('inserttable', {numCols: 4, numRows: 4});
  135. var tds = editor.body.firstChild.getElementsByTagName('td');
  136. for (var i = 0; i < 6; i++) {
  137. tds[i].innerHTML = 'hello';
  138. }
  139. //合并单元格
  140. setTimeout(function () {
  141. var trs = editor.body.firstChild.getElementsByTagName('tr');
  142. var ut = editor.getUETable(editor.body.firstChild);
  143. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  144. ut.setSelected(cellsRange);
  145. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  146. editor.execCommand('mergecells');
  147. ua.manualDeleteFillData(editor.body);
  148. tds = editor.body.firstChild.getElementsByTagName('td');
  149. equal(tds[0].innerHTML.toLowerCase(), 'hello<br>hello<br>hello<br>hello', '合并单元格,内容复制正确');
  150. //撤销合并单元格的操作,再次合并单元格
  151. editor.execCommand('Undo');
  152. setTimeout(function () {
  153. var trs = editor.body.firstChild.getElementsByTagName('tr');
  154. var ut = editor.getUETable(editor.body.firstChild);
  155. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[1]);
  156. ut.setSelected(cellsRange);
  157. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  158. editor.execCommand('mergecells');
  159. ua.manualDeleteFillData(editor.body);
  160. tds = editor.body.firstChild.getElementsByTagName('td');
  161. equal(tds[0].innerHTML.toLowerCase(), 'hello<br>hello<br>hello<br>hello', '撤销后再次合并单元格,内容复制正确');
  162. start();
  163. }, 50);
  164. }, 50);
  165. stop();
  166. });
  167. /*trace 675 这个trace用例中的操作已经设为非法*/
  168. /*trace 685*/
  169. test('trace 685 合并单元格后,删除行,再撤销,再删除行', function () {
  170. var editor = te.obj[0];
  171. var range = te.obj[1];
  172. editor.setContent('<p></p>');
  173. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  174. editor.execCommand('inserttable', {numCols: 4, numRows: 4});
  175. //选择第一行的4格单元格,合并
  176. setTimeout(function () {
  177. var trs = editor.body.firstChild.getElementsByTagName('tr');
  178. var ut = editor.getUETable(editor.body.firstChild);
  179. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[3]);
  180. ut.setSelected(cellsRange);
  181. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  182. var tds = editor.body.getElementsByTagName('td');
  183. editor.execCommand('mergecells');
  184. ok(tds[0].colSpan == 4 && tds[0].rowSpan == 1, '第一行的4个单元格合并成一个');
  185. //选择第2,3,4行的第1个单元格,合并
  186. setTimeout(function () {
  187. var trs = editor.body.firstChild.getElementsByTagName('tr');
  188. var ut = editor.getUETable(editor.body.firstChild);
  189. var cellsRange = ut.getCellsRange(trs[1].cells[0], trs[3].cells[0]);
  190. ut.setSelected(cellsRange);
  191. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  192. var tds = editor.body.getElementsByTagName('td');
  193. editor.execCommand('mergecells');
  194. ok(tds[1].colSpan == 1 && tds[1].rowSpan == 3, '第2,3,4行的第一个单元格合并成一个');
  195. //单击第二步合并的单元格,点击删除行
  196. range.setStart(tds[4], 0).collapse(true).select();
  197. editor.execCommand('deleterow');
  198. equal(editor.body.firstChild.getElementsByTagName('tr').length, 3, '点击删除行,表格剩三行');
  199. //撤销
  200. editor.execCommand('undo');
  201. equal(editor.body.firstChild.getElementsByTagName('tr').length, 4, '撤销后,表格恢复成4行');
  202. //再次点击删除行
  203. range.setStart(tds[4], 0).collapse(true).select();
  204. editor.execCommand('deleterow');
  205. equal(editor.body.firstChild.getElementsByTagName('tr').length, 3, '撤销后,再点击删除行,表格剩三行');
  206. start();
  207. }, 50);
  208. }, 50);
  209. stop();
  210. });
  211. /*trace 711 这个要中文输入法再模拟键盘输入,貌似不能写???*/
  212. /*trace 718*/
  213. test('trace 718 合并单元格后,删除列,再撤销,再删除列', function () {
  214. var editor = te.obj[0];
  215. var range = te.obj[1];
  216. editor.setContent('<p></p>');
  217. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  218. editor.execCommand('inserttable', {numCols: 4, numRows: 4});
  219. //选择中间的4格单元格,合并
  220. setTimeout(function () {
  221. var trs = editor.body.firstChild.getElementsByTagName('tr');
  222. var ut = editor.getUETable(editor.body.firstChild);
  223. var cellsRange = ut.getCellsRange(trs[1].cells[1], trs[2].cells[2]);
  224. ut.setSelected(cellsRange);
  225. range.setStart(trs[1].cells[1], 0).collapse(true).select();
  226. var tds = editor.body.firstChild.getElementsByTagName('td');
  227. editor.execCommand('mergecells');
  228. ok(tds[5].colSpan == 2 && tds[5].rowSpan == 2, '对一个4*4的表格,选择中间的4格单元格,合并成一个');
  229. //光标定位在合并后的大单元格中,点击删除列按钮
  230. range.setStart(tds[5], 0).collapse(true).select();
  231. editor.execCommand('deletecol');
  232. equal(editor.body.firstChild.getElementsByTagName('tr')[0].childNodes.length, 3, '点击删除列,表格剩三列');
  233. //撤销
  234. editor.execCommand('undo');
  235. equal(editor.body.firstChild.getElementsByTagName('tr')[0].childNodes.length, 4, '撤销后,表格剩四列');
  236. //再次点击删除列按钮
  237. //TODO 1.2.6
  238. if (!ua.browser.gecko && !ua.browser.ie) {
  239. range.setStart(tds[5], 0).collapse(true).select();
  240. editor.execCommand('deletecol');
  241. equal(editor.body.firstChild.getElementsByTagName('tr')[0].childNodes.length, 3, '再次点击删除列,表格剩三列');
  242. }
  243. equal(editor.body.firstChild.getElementsByTagName('tr').length, 4, '表格依然有4行');
  244. start();
  245. }, 50);
  246. stop();
  247. });
  248. /*trace 722 需要中文输入法*/
  249. /*trace 743*/
  250. test('trace 743 合并单元格后,删除列,再撤销', function () {
  251. var editor = te.obj[0];
  252. var range = te.obj[1];
  253. editor.setContent('<p></p>');
  254. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  255. editor.execCommand('inserttable', {numCols: 4, numRows: 4});
  256. //第一行的4格单元格,合并
  257. setTimeout(function () {
  258. var trs = editor.body.firstChild.getElementsByTagName('tr');
  259. var ut = editor.getUETable(editor.body.firstChild);
  260. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[3]);
  261. ut.setSelected(cellsRange);
  262. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  263. editor.execCommand('mergecells');
  264. var tds = editor.body.firstChild.getElementsByTagName('td');
  265. ok(tds[0].colSpan == 4 && tds[0].rowSpan == 1 && tds.length == 13, '对一个4*4的表格,选择第一行的4格单元格,合并成一个');
  266. //点击删除列按钮
  267. editor.execCommand('deletecol');
  268. equal(editor.body.firstChild.getElementsByTagName('tr')[1].childNodes.length, 3, '点击删除列,表格剩3列');
  269. //撤销
  270. editor.execCommand('undo');
  271. equal(editor.body.firstChild.getElementsByTagName('tr')[1].childNodes.length, 4, '撤销后,表格恢复成4列');
  272. equal(editor.body.firstChild.getElementsByTagName('tr').length, 4, '表格依然有4行');
  273. start();
  274. }, 50);
  275. stop();
  276. });
  277. /*trace 808 需要观察光标延迟,这个问题已经被标为不修*/
  278. /*trace 855 这个用例描述有问题,而且可以跟trace 584合成一个*/
  279. /*trace 873*/
  280. //test( 'trace 873 光标不在编辑器中时替换一个文本后按撤销', function () {
  281. // if(ua.browser.opera)
  282. // return;
  283. // var editor = te.obj[0];
  284. // editor.setContent('欢迎使用ueditor');
  285. // editor.execCommand( 'searchreplace', {searchStr:'欢迎', replaceStr:'welcom'} );
  286. // ua.manualDeleteFillData(editor.body);
  287. // equal( editor.body.firstChild.innerHTML, 'welcom使用ueditor', '查找替换' );
  288. // editor.execCommand( 'Undo' );
  289. // ua.manualDeleteFillData( editor.body );
  290. // equal( editor.body.firstChild.innerHTML, '欢迎使用ueditor', '撤销' );
  291. //} );
  292. /*trace 942*/
  293. test('trace 942 用格式刷后撤销', function () {
  294. var editor = te.obj[0];
  295. var range = te.obj[1];
  296. var flag = true;
  297. stop();
  298. expect(1);
  299. editor.setContent('<p><strong>hello</strong></p><p><a href="http://www.baidu.com/">hello</a></p>');
  300. range.setStart(editor.body.firstChild.firstChild.firstChild, 2).setEnd(editor.body.firstChild.firstChild.firstChild, 4).select();
  301. editor.addListener('mouseup', function () {
  302. ua.manualDeleteFillData(editor.body);
  303. //从浏览器复制了不可见的空文本
  304. equal(editor.body.lastChild.firstChild.innerHTML.toLowerCase(), 'h<strong></strong>ello');
  305. });
  306. editor.execCommand('formatmatch');
  307. range.setStart(editor.body.lastChild.firstChild.firstChild, 1).collapse(true).select();
  308. ua.mouseup(editor.body);
  309. setTimeout(function () {
  310. start();
  311. }, 100);
  312. });
  313. test('undo--redo', function () {
  314. var editor = te.obj[0];
  315. var range = te.obj[1];
  316. editor.setContent('<p></p>');
  317. editor.focus();
  318. editor.execCommand('anchor', 'hello');
  319. editor.undoManger.undo();
  320. var spase = ua.browser.ie ? '&nbsp;' : '<br>';
  321. equal(ua.getChildHTML(editor.body), '<p>' + spase + '</p>', '');
  322. editor.undoManger.redo();
  323. ua.manualDeleteFillData(editor.body);
  324. // var cs=editor.body.firstChild.firstChild.getAttribute('class');
  325. // var an=editor.body.firstChild.firstChild.getAttribute('anchorname');
  326. // equal(cs,'anchorclass','锚点class');
  327. // equal(an,'hello','锚点name');
  328. // var br = (ua.browser.ie) ? '' : '<br>';
  329. if (ua.browser.ie)
  330. equal(ua.getChildHTML(editor.body), '<p><img class=\"anchorclass\" anchorname=\"hello\">' + spase + '</p>', '');
  331. else
  332. equal(ua.getChildHTML(editor.body), '<p><img anchorname=\"hello\" class=\"anchorclass\">' + spase + '</p>', '');
  333. });
  334. test('reset,index', function () {
  335. var editor = te.obj[0];
  336. editor.setContent('<p></p>');
  337. editor.focus();
  338. editor.execCommand('anchor', 'hello');
  339. var listLength = editor.undoManger.list.length;
  340. ok(listLength > 0, '检查undoManger.list');
  341. equal(editor.undoManger.index, 1, '检查undoManger.index');
  342. editor.undoManger.undo();
  343. equal(editor.undoManger.list.length, listLength, 'undo操作,undoManger.list不变');
  344. equal(editor.undoManger.index, 0, 'undo操作,undoManger.index-1');
  345. var spase = ua.browser.ie ? '&nbsp;' : '<br>';
  346. equal(ua.getChildHTML(editor.body), '<p>' + spase + '</p>', '检查内容');
  347. editor.reset();
  348. equal(editor.undoManger.list.length, 0, 'reset,undoManger.list清空');
  349. equal(editor.undoManger.index, 0, 'reset,undoManger.index清空');
  350. editor.undoManger.redo();
  351. ua.manualDeleteFillData(editor.body);
  352. var spase = ua.browser.ie ? '&nbsp;' : '<br>';
  353. equal(ua.getChildHTML(editor.body), '<p>' + spase + '</p>', '检查内容');
  354. });
  355. /*trace 1068 格式刷图片*/
  356. test('trace 1068 默认样式的图片刷左浮动图片,撤销,左浮动图片刷默认样式的图片', function () {
  357. var editor = te.obj[0];
  358. var range = te.obj[1];
  359. var num = 0;
  360. var body = editor.body;
  361. editor.setContent('<p><br></p>');
  362. range.setStart(body.firstChild, 0).collapse(1).select();
  363. editor.execCommand('insertimage', {src: 'http://img.baidu.com/hi/jx2/j_0001.gif', width: 50, height: 51});
  364. range.selectNode(editor.body.getElementsByTagName('img')[0]).select();
  365. editor.execCommand('imagefloat', 'none');
  366. range.setStart(body.firstChild, 0).collapse(1).select();
  367. editor.execCommand('insertimage', {src: 'http://img.baidu.com/hi/jx2/j_0002.gif', width: 50, height: 51});
  368. range.selectNode(editor.body.getElementsByTagName('img')[0]).select();
  369. editor.execCommand('imagefloat', 'left');
  370. // equal(ua.getFloatStyle(body.getElementsByTagName( 'img' )[0]), "left", '左浮动' );
  371. // equal(ua.getFloatStyle(body.getElementsByTagName( 'img' )[1]), "none", '默认' );
  372. range.selectNode(body.getElementsByTagName('img')[1]).select();
  373. editor.addListener('mouseup', function () {
  374. equal(editor.queryCommandState('formatmatch'), 0, '刷后状态为0');
  375. if (num == 1) {
  376. equal(ua.getFloatStyle(body.getElementsByTagName('img')[0]), "none", '默认刷左浮动');
  377. editor.execCommand('Undo');
  378. equal(ua.getFloatStyle(body.getElementsByTagName('img')[0]), "left", '撤销后,左浮动还原');
  379. range.selectNode(body.getElementsByTagName('img')[0]).select();
  380. editor.execCommand('formatmatch');
  381. range.selectNode(body.getElementsByTagName('img')[1]).select();
  382. num = 2;
  383. ua.mouseup(editor.body);
  384. }
  385. else if (num == 2) {
  386. if (!ua.browser.opera) {
  387. equal(ua.getFloatStyle(body.getElementsByTagName('img')[1]), 'left', '左浮动刷默认');
  388. }
  389. setTimeout(function () {
  390. start();
  391. }, 100);
  392. }
  393. });
  394. editor.execCommand('formatmatch');
  395. range.selectNode(body.getElementsByTagName('img')[0]).select();
  396. num = 1;
  397. ua.mouseup(body.getElementsByTagName('img')[0]);
  398. stop();
  399. });
  400. //test(
  401. // 'undo',
  402. // function() {
  403. // var editor = new baidu.editor.Editor({
  404. // enterkey : 'br',
  405. // initialContent : 'test'
  406. // });
  407. // editor.render(te.dom[0]);
  408. // var domUtils = baidu.editor.dom.domUtils, dtd = baidu.editor.dom.dtd, range = new baidu.editor.dom.Range(
  409. // editor.document);
  410. // editor.setContent('<b>xxxx</b><p>xxxx</p>');
  411. // range.selectNodeContents(editor.document.body).select();
  412. // editor.execCommand('bold');
  413. // editor.execCommand('Undo');
  414. // equals(getHTML(editor.document.body), '<b>xxxx</b><p>xxxx</p>');
  415. // editor.execCommand('redo');
  416. // equals(getHTML(editor.document.body), 'xxxx<p>xxxx</p>');
  417. // ok(!editor.hasRedo);
  418. //
  419. // editor.execCommand('Undo');
  420. // editor.execCommand('Undo');
  421. // equals(getHTML(editor.document.body), 'test');
  422. // });
  423. test('ctrl+z/y', function () {
  424. var editor = te.obj[0];
  425. var range = te.obj[1];
  426. var body = editor.body;
  427. editor.setContent('<p>没有加粗的文本</p>');
  428. range.selectNode(body.firstChild).select();
  429. var p = body.firstChild;
  430. setTimeout(function () {
  431. ua.keydown(editor.body, {'keyCode': 66, 'ctrlKey': true});
  432. setTimeout(function () {
  433. equal(ua.getChildHTML(p), '<strong>没有加粗的文本</strong>');
  434. ua.keydown(editor.body, {'keyCode': 90, 'ctrlKey': true});
  435. setTimeout(function () {
  436. editor.focus();
  437. equal(ua.getChildHTML(body.firstChild), '没有加粗的文本');
  438. ua.keydown(editor.body, {'keyCode': 89, 'ctrlKey': true});
  439. editor.focus();
  440. setTimeout(function () {
  441. equal(ua.getChildHTML(body.firstChild), '<strong>没有加粗的文本</strong>');
  442. start();
  443. }, 100);
  444. }, 100);
  445. }, 150);
  446. }, 100);
  447. stop();
  448. });
  449. /*trace 3209 格式刷图片*/
  450. test('trace 3209 插入表格,undo redo', function () {
  451. var editor = te.obj[0];
  452. var range = te.obj[1];
  453. editor.setContent('<p></p>');
  454. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  455. editor.execCommand('inserttable');
  456. editor.execCommand('undo');
  457. equal(editor.getContent().toLowerCase(), '', '插入表格,撤销');
  458. editor.execCommand('redo');
  459. ua.manualDeleteFillData(editor.body);
  460. equal(editor.body.firstChild.tagName.toLowerCase(), 'table', '插入表格,撤销重做');
  461. });