deletecontent.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Document from '../../src/model/document';
  6. import Position from '../../src/model/position';
  7. import Range from '../../src/model/range';
  8. import Element from '../../src/model/element';
  9. import deleteContent from '../../src/controller/deletecontent';
  10. import { setData, getData } from '../../src/dev-utils/model';
  11. describe( 'DataController', () => {
  12. let doc;
  13. describe( 'deleteContent', () => {
  14. describe( 'in simple scenarios', () => {
  15. beforeEach( () => {
  16. doc = new Document();
  17. doc.createRoot();
  18. const schema = doc.schema;
  19. schema.registerItem( 'image', '$inline' );
  20. schema.allow( { name: '$text', inside: '$root' } );
  21. schema.allow( { name: 'image', inside: '$root' } );
  22. } );
  23. test(
  24. 'does nothing on collapsed selection',
  25. 'f[]oo',
  26. 'f[]oo'
  27. );
  28. test(
  29. 'deletes single character',
  30. 'f[o]o',
  31. 'f[]o'
  32. );
  33. it( 'deletes single character (backward selection)' , () => {
  34. setData( doc, 'f[o]o', { lastRangeBackward: true } );
  35. deleteContent( doc.selection, doc.batch() );
  36. expect( getData( doc ) ).to.equal( 'f[]o' );
  37. } );
  38. test(
  39. 'deletes whole text',
  40. '[foo]',
  41. '[]'
  42. );
  43. test(
  44. 'deletes whole text between nodes',
  45. '<image></image>[foo]<image></image>',
  46. '<image></image>[]<image></image>'
  47. );
  48. test(
  49. 'deletes an element',
  50. 'x[<image></image>]y',
  51. 'x[]y'
  52. );
  53. test(
  54. 'deletes a bunch of nodes',
  55. 'w[x<image></image>y]z',
  56. 'w[]z'
  57. );
  58. test(
  59. 'does not break things when option.merge passed',
  60. 'w[x<image></image>y]z',
  61. 'w[]z',
  62. { merge: true }
  63. );
  64. } );
  65. describe( 'with text attributes', () => {
  66. beforeEach( () => {
  67. doc = new Document();
  68. doc.createRoot();
  69. const schema = doc.schema;
  70. schema.registerItem( 'image', '$inline' );
  71. schema.registerItem( 'paragraph', '$block' );
  72. schema.allow( { name: '$text', inside: '$root' } );
  73. schema.allow( { name: '$text', attributes: [ 'bold', 'italic' ] } );
  74. } );
  75. it( 'deletes characters (first half has attrs)', () => {
  76. setData( doc, '<$text bold="true">fo[o</$text>b]ar' );
  77. deleteContent( doc.selection, doc.batch() );
  78. expect( getData( doc ) ).to.equal( '<$text bold="true">fo[]</$text>ar' );
  79. expect( doc.selection.getAttribute( 'bold' ) ).to.equal( true );
  80. } );
  81. it( 'deletes characters (2nd half has attrs)', () => {
  82. setData( doc, 'fo[o<$text bold="true">b]ar</$text>' );
  83. deleteContent( doc.selection, doc.batch() );
  84. expect( getData( doc ) ).to.equal( 'fo[]<$text bold="true">ar</$text>' );
  85. expect( doc.selection.getAttribute( 'bold' ) ).to.undefined;
  86. } );
  87. it( 'clears selection attrs when emptied content', () => {
  88. setData( doc, '<paragraph>x</paragraph><paragraph>[<$text bold="true">foo</$text>]</paragraph><paragraph>y</paragraph>' );
  89. deleteContent( doc.selection, doc.batch() );
  90. expect( getData( doc ) ).to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>y</paragraph>' );
  91. expect( doc.selection.getAttribute( 'bold' ) ).to.undefined;
  92. } );
  93. it( 'leaves selection attributes when text contains them', () => {
  94. setData(
  95. doc,
  96. '<paragraph>x<$text bold="true">a[foo]b</$text>y</paragraph>',
  97. {
  98. selectionAttributes: {
  99. bold: true
  100. }
  101. }
  102. );
  103. deleteContent( doc.selection, doc.batch() );
  104. expect( getData( doc ) ).to.equal( '<paragraph>x<$text bold="true">a[]b</$text>y</paragraph>' );
  105. expect( doc.selection.getAttribute( 'bold' ) ).to.equal( true );
  106. } );
  107. } );
  108. // Note: The algorithm does not care what kind of it's merging as it knows nothing useful about these elements.
  109. // In most cases it handles all elements like you'd expect to handle block elements in HTML. However,
  110. // in some scenarios where the tree depth is bigger results may be hard to justify. In fact, such cases
  111. // should not happen unless we're talking about lists or tables, but these features will need to cover
  112. // their scenarios themselves. In all generic scenarios elements are never nested.
  113. //
  114. // You may also be thinking – but I don't want my elements to be merged. It means that there are some special rules,
  115. // like – multiple editing hosts (cE=true/false in use) or block limit elements like <td>.
  116. // Those case should, again, be handled by their specific implementations.
  117. describe( 'in multi-element scenarios', () => {
  118. beforeEach( () => {
  119. doc = new Document();
  120. doc.createRoot();
  121. const schema = doc.schema;
  122. schema.registerItem( 'paragraph', '$block' );
  123. schema.registerItem( 'heading1', '$block' );
  124. schema.registerItem( 'pchild' );
  125. schema.registerItem( 'pparent' );
  126. schema.registerItem( 'image', '$inline' );
  127. schema.allow( { name: 'pchild', inside: 'paragraph' } );
  128. schema.allow( { name: '$text', inside: 'pchild' } );
  129. schema.allow( { name: 'paragraph', inside: 'pparent' } );
  130. schema.allow( { name: 'pparent', inside: '$root' } );
  131. schema.allow( { name: '$text', inside: 'pparent' } );
  132. schema.allow( { name: 'paragraph', attributes: [ 'align' ] } );
  133. } );
  134. test(
  135. 'do not merge when no need to',
  136. '<paragraph>x</paragraph><paragraph>[foo]</paragraph><paragraph>y</paragraph>',
  137. '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>y</paragraph>',
  138. { merge: true }
  139. );
  140. test(
  141. 'merges second element into the first one (same name)',
  142. '<paragraph>x</paragraph><paragraph>fo[o</paragraph><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  143. '<paragraph>x</paragraph><paragraph>fo[]ar</paragraph><paragraph>y</paragraph>',
  144. { merge: true }
  145. );
  146. test(
  147. 'does not merge second element into the first one (same name, !option.merge)',
  148. '<paragraph>x</paragraph><paragraph>fo[o</paragraph><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  149. '<paragraph>x</paragraph><paragraph>fo[]</paragraph><paragraph>ar</paragraph><paragraph>y</paragraph>'
  150. );
  151. test(
  152. 'merges second element into the first one (same name)',
  153. '<paragraph>x</paragraph><paragraph>fo[o</paragraph><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  154. '<paragraph>x</paragraph><paragraph>fo[]ar</paragraph><paragraph>y</paragraph>',
  155. { merge: true }
  156. );
  157. test(
  158. 'merges second element into the first one (different name)',
  159. '<paragraph>x</paragraph><heading1>fo[o</heading1><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  160. '<paragraph>x</paragraph><heading1>fo[]ar</heading1><paragraph>y</paragraph>',
  161. { merge: true }
  162. );
  163. // Note: in all these cases we ignore the direction of merge.
  164. // If https://github.com/ckeditor/ckeditor5-engine/issues/470 was fixed we could differently treat
  165. // forward and backward delete.
  166. it( 'merges second element into the first one (different name, backward selection)', () => {
  167. setData(
  168. doc,
  169. '<paragraph>x</paragraph><heading1>fo[o</heading1><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  170. { lastRangeBackward: true }
  171. );
  172. deleteContent( doc.selection, doc.batch(), { merge: true } );
  173. expect( getData( doc ) ).to.equal( '<paragraph>x</paragraph><heading1>fo[]ar</heading1><paragraph>y</paragraph>' );
  174. } );
  175. test(
  176. 'merges second element into the first one (different attrs)',
  177. '<paragraph>x</paragraph><paragraph align="l">fo[o</paragraph><paragraph>b]ar</paragraph><paragraph>y</paragraph>',
  178. '<paragraph>x</paragraph><paragraph align="l">fo[]ar</paragraph><paragraph>y</paragraph>',
  179. { merge: true }
  180. );
  181. test(
  182. 'merges second element to an empty first element',
  183. '<paragraph>x</paragraph><heading1>[</heading1><paragraph>fo]o</paragraph><paragraph>y</paragraph>',
  184. '<paragraph>x</paragraph><heading1>[]o</heading1><paragraph>y</paragraph>',
  185. { merge: true }
  186. );
  187. test(
  188. 'leaves just one element when all selected',
  189. '<heading1>[x</heading1><paragraph>foo</paragraph><paragraph>y]</paragraph>',
  190. '<heading1>[]</heading1>',
  191. { merge: true }
  192. );
  193. it( 'uses remove delta instead of merge delta if merged element is empty', () => {
  194. setData( doc, '<paragraph>ab[cd</paragraph><paragraph>efgh]</paragraph>' );
  195. const batch = doc.batch();
  196. const spyMerge = sinon.spy( batch, 'merge' );
  197. const spyRemove = sinon.spy( batch, 'remove' );
  198. deleteContent( doc.selection, batch, { merge: true } );
  199. expect( getData( doc ) ).to.equal( '<paragraph>ab[]</paragraph>' );
  200. expect( spyMerge.called ).to.be.false;
  201. expect( spyRemove.called ).to.be.true;
  202. } );
  203. // Note: in all these cases we ignore the direction of merge.
  204. // If https://github.com/ckeditor/ckeditor5-engine/issues/470 was fixed we could differently treat
  205. // forward and backward delete.
  206. describe( 'with nested elements', () => {
  207. test(
  208. 'merges elements when deep nested',
  209. '<paragraph>x<pchild>fo[o</pchild></paragraph><paragraph><pchild>b]ar</pchild>y</paragraph>',
  210. '<paragraph>x<pchild>fo[]ar</pchild>y</paragraph>',
  211. { merge: true }
  212. );
  213. it( 'merges elements when deep nested (3rd level)', () => {
  214. const root = doc.getRoot();
  215. // We need to use the raw API due to https://github.com/ckeditor/ckeditor5-engine/issues/905.
  216. // <pparent>x<paragraph>x<pchild>fo[o</pchild></paragraph></pparent>
  217. // <pparent><paragraph><pchild>b]ar</pchild>y</paragraph>y</pparent>
  218. root.appendChildren(
  219. new Element( 'pparent', null, [
  220. 'x',
  221. new Element( 'paragraph', null, [
  222. 'x',
  223. new Element( 'pchild', null, 'foo' )
  224. ] )
  225. ] )
  226. );
  227. root.appendChildren(
  228. new Element( 'pparent', null, [
  229. new Element( 'paragraph', null, [
  230. new Element( 'pchild', null, 'bar' ),
  231. 'y'
  232. ] ),
  233. 'y'
  234. ] )
  235. );
  236. const range = new Range(
  237. new Position( doc.getRoot(), [ 0, 1, 1, 2 ] ), // fo[o
  238. new Position( doc.getRoot(), [ 1, 0, 0, 1 ] ) // b]ar
  239. );
  240. doc.selection.setRanges( [ range ] );
  241. deleteContent( doc.selection, doc.batch(), { merge: true } );
  242. expect( getData( doc ) )
  243. .to.equal( '<pparent>x<paragraph>x<pchild>fo[]ar</pchild>y</paragraph>y</pparent>' );
  244. } );
  245. test(
  246. 'merges elements when left end deep nested',
  247. '<paragraph>x<pchild>fo[o</pchild></paragraph><paragraph>b]ary</paragraph><paragraph>x</paragraph>',
  248. '<paragraph>x<pchild>fo[]ary</pchild></paragraph><paragraph>x</paragraph>',
  249. { merge: true }
  250. );
  251. test(
  252. 'merges elements when right end deep nested',
  253. '<paragraph>x</paragraph><paragraph>fo[o</paragraph><paragraph><pchild>b]ar</pchild>x</paragraph>',
  254. '<paragraph>x</paragraph><paragraph>fo[]ar</paragraph><paragraph>x</paragraph>',
  255. { merge: true }
  256. );
  257. it( 'merges elements when left end deep nested (3rd level)', () => {
  258. const root = doc.getRoot();
  259. // We need to use the raw API due to https://github.com/ckeditor/ckeditor5-engine/issues/905.
  260. // <pparent>x<paragraph>foo<pchild>ba[r</pchild></paragraph></pparent><paragraph>b]om</paragraph>
  261. root.appendChildren(
  262. new Element( 'pparent', null, [
  263. 'x',
  264. new Element( 'paragraph', null, [
  265. 'foo',
  266. new Element( 'pchild', null, 'bar' )
  267. ] )
  268. ] )
  269. );
  270. root.appendChildren(
  271. new Element( 'paragraph', null, 'bom' )
  272. );
  273. const range = new Range(
  274. new Position( doc.getRoot(), [ 0, 1, 3, 2 ] ), // ba[r
  275. new Position( doc.getRoot(), [ 1, 1 ] ) // b]om
  276. );
  277. doc.selection.setRanges( [ range ] );
  278. deleteContent( doc.selection, doc.batch(), { merge: true } );
  279. expect( getData( doc ) )
  280. .to.equal( '<pparent>x<paragraph>foo<pchild>ba[]om</pchild></paragraph></pparent>' );
  281. } );
  282. } );
  283. describe( 'with object elements', () => {
  284. beforeEach( () => {
  285. const schema = doc.schema;
  286. schema.registerItem( 'blockWidget' );
  287. schema.registerItem( 'nestedEditable' );
  288. schema.allow( { name: 'blockWidget', inside: '$root' } );
  289. schema.allow( { name: 'nestedEditable', inside: 'blockWidget' } );
  290. schema.allow( { name: '$text', inside: 'nestedEditable' } );
  291. schema.objects.add( 'blockWidget' );
  292. schema.limits.add( 'nestedEditable' );
  293. } );
  294. test(
  295. 'does not merge an object element (if it is first)',
  296. '<blockWidget><nestedEditable>fo[o</nestedEditable></blockWidget><paragraph>b]ar</paragraph>',
  297. '<blockWidget><nestedEditable>fo[]</nestedEditable></blockWidget><paragraph>ar</paragraph>',
  298. { merge: true }
  299. );
  300. test(
  301. 'does not merge an object element (if it is second)',
  302. '<paragraph>ba[r</paragraph><blockWidget><nestedEditable>f]oo</nestedEditable></blockWidget>',
  303. '<paragraph>ba[]</paragraph><blockWidget><nestedEditable>oo</nestedEditable></blockWidget>',
  304. { merge: true }
  305. );
  306. } );
  307. } );
  308. describe( 'in element selections scenarios', () => {
  309. beforeEach( () => {
  310. doc = new Document();
  311. // <p> like root.
  312. doc.createRoot( 'paragraph', 'paragraphRoot' );
  313. // <body> like root.
  314. doc.createRoot( '$root', 'bodyRoot' );
  315. // Special root which allows only blockWidgets inside itself.
  316. doc.createRoot( 'restrictedRoot', 'restrictedRoot' );
  317. const schema = doc.schema;
  318. schema.registerItem( 'image', '$inline' );
  319. schema.registerItem( 'paragraph', '$block' );
  320. schema.registerItem( 'heading1', '$block' );
  321. schema.registerItem( 'blockWidget' );
  322. schema.registerItem( 'restrictedRoot' );
  323. schema.allow( { name: '$block', inside: '$root' } );
  324. schema.allow( { name: 'blockWidget', inside: '$root' } );
  325. schema.allow( { name: 'blockWidget', inside: 'restrictedRoot' } );
  326. } );
  327. // See also "in simple scenarios => deletes an element".
  328. it( 'deletes two inline elements', () => {
  329. setData(
  330. doc,
  331. 'x[<image></image><image></image>]z',
  332. { rootName: 'paragraphRoot' }
  333. );
  334. deleteContent( doc.selection, doc.batch() );
  335. expect( getData( doc, { rootName: 'paragraphRoot' } ) )
  336. .to.equal( 'x[]z' );
  337. } );
  338. it( 'creates a paragraph when text is not allowed (paragraph selected)', () => {
  339. setData(
  340. doc,
  341. '<paragraph>x</paragraph>[<paragraph>yyy</paragraph>]<paragraph>z</paragraph>',
  342. { rootName: 'bodyRoot' }
  343. );
  344. deleteContent( doc.selection, doc.batch() );
  345. expect( getData( doc, { rootName: 'bodyRoot' } ) )
  346. .to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
  347. } );
  348. it( 'creates a paragraph when text is not allowed (block widget selected)', () => {
  349. setData(
  350. doc,
  351. '<paragraph>x</paragraph>[<blockWidget></blockWidget>]<paragraph>z</paragraph>',
  352. { rootName: 'bodyRoot' }
  353. );
  354. deleteContent( doc.selection, doc.batch() );
  355. expect( getData( doc, { rootName: 'bodyRoot' } ) )
  356. .to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
  357. } );
  358. it( 'creates paragraph when text is not allowed (heading selected)', () => {
  359. setData(
  360. doc,
  361. '<paragraph>x</paragraph>[<heading1>yyy</heading1>]<paragraph>z</paragraph>',
  362. { rootName: 'bodyRoot' }
  363. );
  364. deleteContent( doc.selection, doc.batch() );
  365. expect( getData( doc, { rootName: 'bodyRoot' } ) )
  366. .to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
  367. } );
  368. it( 'creates paragraph when text is not allowed (two blocks selected)', () => {
  369. setData(
  370. doc,
  371. '<paragraph>x</paragraph>[<heading1>yyy</heading1><paragraph>yyy</paragraph>]<paragraph>z</paragraph>',
  372. { rootName: 'bodyRoot' }
  373. );
  374. deleteContent( doc.selection, doc.batch() );
  375. expect( getData( doc, { rootName: 'bodyRoot' } ) )
  376. .to.equal( '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>z</paragraph>' );
  377. } );
  378. it( 'creates paragraph when text is not allowed (all content selected)', () => {
  379. setData(
  380. doc,
  381. '[<heading1>x</heading1><paragraph>z</paragraph>]',
  382. { rootName: 'bodyRoot' }
  383. );
  384. deleteContent( doc.selection, doc.batch() );
  385. expect( getData( doc, { rootName: 'bodyRoot' } ) )
  386. .to.equal( '<paragraph>[]</paragraph>' );
  387. } );
  388. it( 'does not create a paragraph when it is not allowed', () => {
  389. setData(
  390. doc,
  391. '<blockWidget></blockWidget>[<blockWidget></blockWidget>]<blockWidget></blockWidget>',
  392. { rootName: 'restrictedRoot' }
  393. );
  394. deleteContent( doc.selection, doc.batch() );
  395. expect( getData( doc, { rootName: 'restrictedRoot' } ) )
  396. .to.equal( '<blockWidget></blockWidget>[]<blockWidget></blockWidget>' );
  397. } );
  398. } );
  399. describe( 'integration with inline limit elements', () => {
  400. beforeEach( () => {
  401. doc = new Document();
  402. doc.createRoot();
  403. const schema = doc.schema;
  404. schema.registerItem( 'inlineLimit' );
  405. schema.allow( { name: 'inlineLimit', inside: '$root' } );
  406. schema.allow( { name: '$text', inside: 'inlineLimit' } );
  407. schema.limits.add( 'inlineLimit' );
  408. schema.allow( { name: '$inline', inside: '$root' } );
  409. schema.registerItem( 'x' );
  410. schema.allow( { name: '$text', inside: 'x' } );
  411. schema.allow( { name: 'x', inside: '$root' } );
  412. } );
  413. test(
  414. 'should delete inside inline limit element',
  415. '<inlineLimit>foo [bar] baz</inlineLimit>',
  416. '<inlineLimit>foo [] baz</inlineLimit>'
  417. );
  418. test(
  419. 'should delete whole inline limit element',
  420. 'x[<inlineLimit>foo bar</inlineLimit>]x',
  421. 'x[]x'
  422. );
  423. test(
  424. 'should delete from two inline limit elements',
  425. '<inlineLimit>foo [bar</inlineLimit><inlineLimit>baz] qux</inlineLimit>',
  426. '<inlineLimit>foo []</inlineLimit><inlineLimit> qux</inlineLimit>'
  427. );
  428. test(
  429. 'merge option should be ignored if both elements are limits',
  430. '<inlineLimit>foo [bar</inlineLimit><inlineLimit>baz] qux</inlineLimit>',
  431. '<inlineLimit>foo []</inlineLimit><inlineLimit> qux</inlineLimit>',
  432. { merge: true }
  433. );
  434. test(
  435. 'merge option should be ignored if the first element is a limit',
  436. '<inlineLimit>foo [bar</inlineLimit><x>baz] qux</x>',
  437. '<inlineLimit>foo []</inlineLimit><x> qux</x>',
  438. { merge: true }
  439. );
  440. test(
  441. 'merge option should be ignored if the second element is a limit',
  442. '<x>baz [qux</x><inlineLimit>foo] bar</inlineLimit>',
  443. '<x>baz []</x><inlineLimit> bar</inlineLimit>',
  444. { merge: true }
  445. );
  446. } );
  447. describe( 'integration with block limit elements', () => {
  448. beforeEach( () => {
  449. doc = new Document();
  450. doc.createRoot();
  451. const schema = doc.schema;
  452. schema.registerItem( 'blockLimit' );
  453. schema.allow( { name: 'blockLimit', inside: '$root' } );
  454. schema.allow( { name: '$block', inside: 'blockLimit' } );
  455. schema.limits.add( 'blockLimit' );
  456. schema.registerItem( 'paragraph', '$block' );
  457. } );
  458. test(
  459. 'should delete inside block limit element',
  460. '<blockLimit><paragraph>fo[o</paragraph><paragraph>b]ar</paragraph></blockLimit>',
  461. '<blockLimit><paragraph>fo[]</paragraph><paragraph>ar</paragraph></blockLimit>'
  462. );
  463. test(
  464. 'should delete inside block limit element (with merge)',
  465. '<blockLimit><paragraph>fo[o</paragraph><paragraph>b]ar</paragraph></blockLimit>',
  466. '<blockLimit><paragraph>fo[]ar</paragraph></blockLimit>',
  467. { merge: true }
  468. );
  469. test(
  470. 'should delete whole block limit element',
  471. '<paragraph>x</paragraph>[<blockLimit><paragraph>foo</paragraph></blockLimit>]<paragraph>x</paragraph>',
  472. '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>x</paragraph>'
  473. );
  474. test(
  475. 'should delete from two block limit elements',
  476. '<blockLimit><paragraph>foo [bar</paragraph></blockLimit><blockLimit><paragraph>baz] qux</paragraph></blockLimit>',
  477. '<blockLimit><paragraph>foo []</paragraph></blockLimit><blockLimit><paragraph> qux</paragraph></blockLimit>'
  478. );
  479. test(
  480. 'merge option should be ignored if any of the elements is a limit',
  481. '<blockLimit><paragraph>foo [bar</paragraph></blockLimit><blockLimit><paragraph>baz] qux</paragraph></blockLimit>',
  482. '<blockLimit><paragraph>foo []</paragraph></blockLimit><blockLimit><paragraph> qux</paragraph></blockLimit>',
  483. { merge: true }
  484. );
  485. } );
  486. function test( title, input, output, options ) {
  487. it( title, () => {
  488. setData( doc, input );
  489. deleteContent( doc.selection, doc.batch(), options );
  490. expect( getData( doc ) ).to.equal( output );
  491. } );
  492. }
  493. } );
  494. } );