8
0

selection.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Model from '../../src/model/model';
  6. import Element from '../../src/model/element';
  7. import Text from '../../src/model/text';
  8. import Range from '../../src/model/range';
  9. import Position from '../../src/model/position';
  10. import LiveRange from '../../src/model/liverange';
  11. import Selection from '../../src/model/selection';
  12. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  13. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  14. import count from '@ckeditor/ckeditor5-utils/src/count';
  15. import { parse, setData } from '../../src/dev-utils/model';
  16. import Schema from '../../src/model/schema';
  17. testUtils.createSinonSandbox();
  18. describe( 'Selection', () => {
  19. let model, doc, root, selection, liveRange, range, range1, range2, range3;
  20. beforeEach( () => {
  21. model = new Model();
  22. doc = model.document;
  23. root = doc.createRoot();
  24. root.appendChildren( [
  25. new Element( 'p' ),
  26. new Element( 'p' ),
  27. new Element( 'p', [], new Text( 'foobar' ) ),
  28. new Element( 'p' ),
  29. new Element( 'p' ),
  30. new Element( 'p' ),
  31. new Element( 'p', [], new Text( 'foobar' ) )
  32. ] );
  33. selection = new Selection();
  34. liveRange = new LiveRange( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
  35. range = new Range( new Position( root, [ 2 ] ), new Position( root, [ 2, 2 ] ) );
  36. range1 = new Range( new Position( root, [ 1 ] ), new Position( root, [ 4 ] ) );
  37. range2 = new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) );
  38. range3 = new Range( new Position( root, [ 6 ] ), new Position( root, [ 7 ] ) );
  39. } );
  40. afterEach( () => {
  41. model.destroy();
  42. liveRange.detach();
  43. } );
  44. describe( 'constructor()', () => {
  45. it( 'should be able to create an empty selection', () => {
  46. const selection = new Selection();
  47. expect( Array.from( selection.getRanges() ) ).to.deep.equal( [] );
  48. } );
  49. it( 'should be able to create a selection from the given ranges', () => {
  50. const ranges = [ range1, range2, range3 ];
  51. const selection = new Selection( ranges );
  52. expect( Array.from( selection.getRanges() ) ).to.deep.equal( ranges );
  53. } );
  54. it( 'should be able to create a selection from the given ranges and isLastBackward flag', () => {
  55. const ranges = [ range1, range2, range3 ];
  56. const selection = new Selection( ranges, true );
  57. expect( selection.isBackward ).to.be.true;
  58. } );
  59. } );
  60. describe( 'isCollapsed', () => {
  61. it( 'should return false for empty selection', () => {
  62. expect( selection.isCollapsed ).to.be.false;
  63. } );
  64. it( 'should return true when there is single collapsed ranges', () => {
  65. selection.setTo( new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) );
  66. expect( selection.isCollapsed ).to.be.true;
  67. } );
  68. it( 'should return false when there are multiple ranges', () => {
  69. selection.setTo( [
  70. new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ),
  71. new Range( new Position( root, [ 2 ] ), new Position( root, [ 2 ] ) )
  72. ] );
  73. expect( selection.isCollapsed ).to.be.false;
  74. } );
  75. it( 'should return false when there is not collapsed range', () => {
  76. selection.setTo( range );
  77. expect( selection.isCollapsed ).to.be.false;
  78. } );
  79. } );
  80. describe( 'rangeCount', () => {
  81. it( 'should return proper range count', () => {
  82. expect( selection.rangeCount ).to.equal( 0 );
  83. selection.setTo( new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) );
  84. expect( selection.rangeCount ).to.equal( 1 );
  85. selection.setTo( [
  86. new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ),
  87. new Range( new Position( root, [ 2 ] ), new Position( root, [ 2 ] ) )
  88. ] );
  89. expect( selection.rangeCount ).to.equal( 2 );
  90. } );
  91. } );
  92. describe( 'isBackward', () => {
  93. it( 'is defined by the last added range', () => {
  94. selection.setTo( [ range ], true );
  95. expect( selection ).to.have.property( 'isBackward', true );
  96. selection.setTo( liveRange );
  97. expect( selection ).to.have.property( 'isBackward', false );
  98. } );
  99. it( 'is false when last range is collapsed', () => {
  100. const pos = Position.createAt( root, 0 );
  101. selection.setTo( [ new Range( pos, pos ) ], true );
  102. expect( selection.isBackward ).to.be.false;
  103. } );
  104. } );
  105. describe( 'focus', () => {
  106. let r1, r2, r3;
  107. beforeEach( () => {
  108. r1 = Range.createFromParentsAndOffsets( root, 2, root, 4 );
  109. r2 = Range.createFromParentsAndOffsets( root, 4, root, 6 );
  110. r3 = Range.createFromParentsAndOffsets( root, 1, root, 2 );
  111. selection.setTo( [ r1, r2 ] );
  112. } );
  113. it( 'should return correct focus when last added range is not backward one', () => {
  114. selection.setTo( [ r1, r2, r3 ] );
  115. expect( selection.focus.isEqual( r3.end ) ).to.be.true;
  116. } );
  117. it( 'should return correct focus when last added range is backward one', () => {
  118. selection.setTo( [ r1, r2, r3 ], true );
  119. expect( selection.focus.isEqual( r3.start ) ).to.be.true;
  120. } );
  121. it( 'should return null if no ranges in selection', () => {
  122. selection.setTo( null );
  123. expect( selection.focus ).to.be.null;
  124. } );
  125. } );
  126. describe( 'setTo() - setting selection inside element', () => {
  127. it( 'should set selection inside an element', () => {
  128. const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
  129. selection.setTo( Range.createIn( element ) );
  130. const ranges = Array.from( selection.getRanges() );
  131. expect( ranges.length ).to.equal( 1 );
  132. expect( ranges[ 0 ].start.parent ).to.equal( element );
  133. expect( ranges[ 0 ].start.offset ).to.deep.equal( 0 );
  134. expect( ranges[ 0 ].end.parent ).to.equal( element );
  135. expect( ranges[ 0 ].end.offset ).to.deep.equal( 6 );
  136. } );
  137. } );
  138. describe( 'setTo() - setting selection on item', () => {
  139. it( 'should set selection on an item', () => {
  140. const textNode1 = new Text( 'foo' );
  141. const textNode2 = new Text( 'bar' );
  142. const textNode3 = new Text( 'baz' );
  143. const element = new Element( 'p', null, [ textNode1, textNode2, textNode3 ] );
  144. selection.setTo( Range.createOn( textNode2 ) );
  145. const ranges = Array.from( selection.getRanges() );
  146. expect( ranges.length ).to.equal( 1 );
  147. expect( ranges[ 0 ].start.parent ).to.equal( element );
  148. expect( ranges[ 0 ].start.offset ).to.deep.equal( 3 );
  149. expect( ranges[ 0 ].end.parent ).to.equal( element );
  150. expect( ranges[ 0 ].end.offset ).to.deep.equal( 6 );
  151. } );
  152. } );
  153. describe( 'setTo() - setting selection to position or item', () => {
  154. it( 'fires change:range', () => {
  155. const spy = sinon.spy();
  156. selection.on( 'change:range', spy );
  157. selection.setTo( root );
  158. expect( spy.calledOnce ).to.be.true;
  159. } );
  160. it( 'sets selection at the 0 offset if second parameter not passed', () => {
  161. selection.setTo( root );
  162. expect( selection ).to.have.property( 'isCollapsed', true );
  163. const focus = selection.focus;
  164. expect( focus ).to.have.property( 'parent', root );
  165. expect( focus ).to.have.property( 'offset', 0 );
  166. } );
  167. it( 'sets selection at given offset in given parent', () => {
  168. selection.setTo( root, 3 );
  169. expect( selection ).to.have.property( 'isCollapsed', true );
  170. const focus = selection.focus;
  171. expect( focus ).to.have.property( 'parent', root );
  172. expect( focus ).to.have.property( 'offset', 3 );
  173. } );
  174. it( 'sets selection at the end of the given parent', () => {
  175. selection.setTo( root, 'end' );
  176. expect( selection ).to.have.property( 'isCollapsed', true );
  177. const focus = selection.focus;
  178. expect( focus ).to.have.property( 'parent', root );
  179. expect( focus ).to.have.property( 'offset', root.maxOffset );
  180. } );
  181. it( 'sets selection before the specified element', () => {
  182. selection.setTo( root.getChild( 1 ), 'before' );
  183. expect( selection ).to.have.property( 'isCollapsed', true );
  184. const focus = selection.focus;
  185. expect( focus ).to.have.property( 'parent', root );
  186. expect( focus ).to.have.property( 'offset', 1 );
  187. } );
  188. it( 'sets selection after the specified element', () => {
  189. selection.setTo( root.getChild( 1 ), 'after' );
  190. expect( selection ).to.have.property( 'isCollapsed', true );
  191. const focus = selection.focus;
  192. expect( focus ).to.have.property( 'parent', root );
  193. expect( focus ).to.have.property( 'offset', 2 );
  194. } );
  195. it( 'sets selection at the specified position', () => {
  196. const pos = Position.createFromParentAndOffset( root, 3 );
  197. selection.setTo( pos );
  198. expect( selection ).to.have.property( 'isCollapsed', true );
  199. const focus = selection.focus;
  200. expect( focus ).to.have.property( 'parent', root );
  201. expect( focus ).to.have.property( 'offset', 3 );
  202. } );
  203. } );
  204. describe( 'setFocus()', () => {
  205. it( 'keeps all existing ranges and fires no change:range when no modifications needed', () => {
  206. selection.setTo( [ range, liveRange ] );
  207. const spy = sinon.spy();
  208. selection.on( 'change:range', spy );
  209. selection.setFocus( selection.focus );
  210. expect( count( selection.getRanges() ) ).to.equal( 2 );
  211. expect( spy.callCount ).to.equal( 0 );
  212. } );
  213. it( 'fires change:range', () => {
  214. selection.setTo( range );
  215. const spy = sinon.spy();
  216. selection.on( 'change:range', spy );
  217. selection.setFocus( Position.createAt( root, 'end' ) );
  218. expect( spy.calledOnce ).to.be.true;
  219. } );
  220. it( 'throws if there are no ranges in selection', () => {
  221. const endPos = Position.createAt( root, 'end' );
  222. expect( () => {
  223. selection.setFocus( endPos );
  224. } ).to.throw( CKEditorError, /model-selection-setFocus-no-ranges/ );
  225. } );
  226. it( 'modifies existing collapsed selection', () => {
  227. const startPos = Position.createAt( root, 1 );
  228. const endPos = Position.createAt( root, 2 );
  229. selection.setTo( startPos );
  230. selection.setFocus( endPos );
  231. expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
  232. expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
  233. } );
  234. it( 'makes existing collapsed selection a backward selection', () => {
  235. const startPos = Position.createAt( root, 1 );
  236. const endPos = Position.createAt( root, 0 );
  237. selection.setTo( startPos );
  238. selection.setFocus( endPos );
  239. expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
  240. expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
  241. expect( selection.isBackward ).to.be.true;
  242. } );
  243. it( 'modifies existing non-collapsed selection', () => {
  244. const startPos = Position.createAt( root, 1 );
  245. const endPos = Position.createAt( root, 2 );
  246. const newEndPos = Position.createAt( root, 3 );
  247. selection.setTo( new Range( startPos, endPos ) );
  248. selection.setFocus( newEndPos );
  249. expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
  250. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  251. } );
  252. it( 'makes existing non-collapsed selection a backward selection', () => {
  253. const startPos = Position.createAt( root, 1 );
  254. const endPos = Position.createAt( root, 2 );
  255. const newEndPos = Position.createAt( root, 0 );
  256. selection.setTo( new Range( startPos, endPos ) );
  257. selection.setFocus( newEndPos );
  258. expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
  259. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  260. expect( selection.isBackward ).to.be.true;
  261. } );
  262. it( 'makes existing backward selection a forward selection', () => {
  263. const startPos = Position.createAt( root, 1 );
  264. const endPos = Position.createAt( root, 2 );
  265. const newEndPos = Position.createAt( root, 3 );
  266. selection.setTo( new Range( startPos, endPos ), true );
  267. selection.setFocus( newEndPos );
  268. expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
  269. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  270. expect( selection.isBackward ).to.be.false;
  271. } );
  272. it( 'modifies existing backward selection', () => {
  273. const startPos = Position.createAt( root, 1 );
  274. const endPos = Position.createAt( root, 2 );
  275. const newEndPos = Position.createAt( root, 0 );
  276. selection.setTo( new Range( startPos, endPos ), true );
  277. selection.setFocus( newEndPos );
  278. expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
  279. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  280. expect( selection.isBackward ).to.be.true;
  281. } );
  282. it( 'modifies only the last range', () => {
  283. // Offsets are chosen in this way that the order of adding ranges must count, not their document order.
  284. const startPos1 = Position.createAt( root, 4 );
  285. const endPos1 = Position.createAt( root, 5 );
  286. const startPos2 = Position.createAt( root, 1 );
  287. const endPos2 = Position.createAt( root, 2 );
  288. const newEndPos = Position.createAt( root, 0 );
  289. selection.setTo( [
  290. new Range( startPos1, endPos1 ),
  291. new Range( startPos2, endPos2 )
  292. ] );
  293. const spy = sinon.spy();
  294. selection.on( 'change:range', spy );
  295. selection.setFocus( newEndPos );
  296. const ranges = Array.from( selection.getRanges() );
  297. expect( ranges ).to.have.lengthOf( 2 );
  298. expect( ranges[ 0 ].start.compareWith( startPos1 ) ).to.equal( 'same' );
  299. expect( ranges[ 0 ].end.compareWith( endPos1 ) ).to.equal( 'same' );
  300. expect( selection.anchor.compareWith( startPos2 ) ).to.equal( 'same' );
  301. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  302. expect( selection.isBackward ).to.be.true;
  303. expect( spy.calledOnce ).to.be.true;
  304. } );
  305. it( 'collapses the selection when extending to the anchor', () => {
  306. const startPos = Position.createAt( root, 1 );
  307. const endPos = Position.createAt( root, 2 );
  308. selection.setTo( new Range( startPos, endPos ) );
  309. selection.setFocus( startPos );
  310. expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
  311. expect( selection.isCollapsed ).to.be.true;
  312. } );
  313. it( 'uses Position.createAt', () => {
  314. const startPos = Position.createAt( root, 1 );
  315. const endPos = Position.createAt( root, 2 );
  316. const newEndPos = Position.createAt( root, 4 );
  317. const spy = testUtils.sinon.stub( Position, 'createAt' ).returns( newEndPos );
  318. selection.setTo( new Range( startPos, endPos ) );
  319. selection.setFocus( root, 'end' );
  320. expect( spy.calledOnce ).to.be.true;
  321. expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
  322. } );
  323. } );
  324. describe( 'setTo - selection set to null', () => {
  325. let spy;
  326. it( 'should remove all stored ranges', () => {
  327. selection.setTo( [ liveRange, range ] );
  328. selection.setTo( null );
  329. expect( Array.from( selection.getRanges() ).length ).to.equal( 0 );
  330. } );
  331. it( 'should fire exactly one change:range event', () => {
  332. selection.setTo( [ liveRange, range ] );
  333. spy = sinon.spy();
  334. selection.on( 'change:range', spy );
  335. selection.setTo( null );
  336. expect( spy.calledOnce ).to.be.true;
  337. } );
  338. it( 'should not fire change:range event if there were no ranges', () => {
  339. spy = sinon.spy();
  340. selection.on( 'change:range', spy );
  341. selection.setTo( null );
  342. expect( spy.called ).to.be.false;
  343. } );
  344. } );
  345. describe( '_setRanges()', () => {
  346. let newRanges, spy;
  347. beforeEach( () => {
  348. newRanges = [
  349. new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) ),
  350. new Range( new Position( root, [ 5, 0 ] ), new Position( root, [ 6, 0 ] ) )
  351. ];
  352. selection.setTo( [ liveRange, range ] );
  353. spy = sinon.spy();
  354. selection.on( 'change:range', spy );
  355. } );
  356. it( 'should throw an error when range is invalid', () => {
  357. expect( () => {
  358. selection._setRanges( [ { invalid: 'range' } ] );
  359. } ).to.throw( CKEditorError, /model-selection-added-not-range/ );
  360. } );
  361. it( 'should remove all ranges and add given ranges', () => {
  362. selection._setRanges( newRanges );
  363. const ranges = Array.from( selection.getRanges() );
  364. expect( ranges ).to.deep.equal( newRanges );
  365. } );
  366. it( 'should use last range from given array to get anchor and focus position', () => {
  367. selection._setRanges( newRanges );
  368. expect( selection.anchor.path ).to.deep.equal( [ 5, 0 ] );
  369. expect( selection.focus.path ).to.deep.equal( [ 6, 0 ] );
  370. } );
  371. it( 'should acknowledge backward flag when setting anchor and focus', () => {
  372. selection._setRanges( newRanges, true );
  373. expect( selection.anchor.path ).to.deep.equal( [ 6, 0 ] );
  374. expect( selection.focus.path ).to.deep.equal( [ 5, 0 ] );
  375. } );
  376. it( 'should fire exactly one change:range event', () => {
  377. selection._setRanges( newRanges );
  378. expect( spy.calledOnce ).to.be.true;
  379. } );
  380. it( 'should fire change:range event with correct parameters', () => {
  381. selection.on( 'change:range', ( evt, data ) => {
  382. expect( data.directChange ).to.be.true;
  383. } );
  384. selection._setRanges( newRanges );
  385. } );
  386. it( 'should not fire change:range event if given ranges are the same', () => {
  387. selection._setRanges( [ liveRange, range ] );
  388. expect( spy.calledOnce ).to.be.false;
  389. } );
  390. } );
  391. describe( 'setTo()', () => {
  392. it( 'should set selection to be same as given selection, using _setRanges method', () => {
  393. const spy = sinon.spy( selection, '_setRanges' );
  394. const otherSelection = new Selection( [ range1, range2 ], true );
  395. selection.setTo( otherSelection );
  396. expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1, range2 ] );
  397. expect( selection.isBackward ).to.be.true;
  398. expect( selection._setRanges.calledOnce ).to.be.true;
  399. spy.restore();
  400. } );
  401. it( 'should set selection on the given Range using _setRanges method', () => {
  402. const spy = sinon.spy( selection, '_setRanges' );
  403. selection.setTo( range1 );
  404. expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1 ] );
  405. expect( selection.isBackward ).to.be.false;
  406. expect( selection._setRanges.calledOnce ).to.be.true;
  407. spy.restore();
  408. } );
  409. it( 'should set selection on the given iterable of Ranges using _setRanges method', () => {
  410. const spy = sinon.spy( selection, '_setRanges' );
  411. selection.setTo( new Set( [ range1, range2 ] ) );
  412. expect( Array.from( selection.getRanges() ) ).to.deep.equal( [ range1, range2 ] );
  413. expect( selection.isBackward ).to.be.false;
  414. expect( selection._setRanges.calledOnce ).to.be.true;
  415. spy.restore();
  416. } );
  417. it( 'should set collapsed selection on the given Position using _setRanges method', () => {
  418. const spy = sinon.spy( selection, '_setRanges' );
  419. const position = new Position( root, [ 4 ] );
  420. selection.setTo( position );
  421. expect( Array.from( selection.getRanges() ).length ).to.equal( 1 );
  422. expect( Array.from( selection.getRanges() )[ 0 ].start ).to.deep.equal( position );
  423. expect( selection.isBackward ).to.be.false;
  424. expect( selection.isCollapsed ).to.be.true;
  425. expect( selection._setRanges.calledOnce ).to.be.true;
  426. spy.restore();
  427. } );
  428. it( 'should throw an error when trying to set selection to not selectable', () => {
  429. expect( () => {
  430. selection.setTo( {} );
  431. } ).to.throw( /model-selection-setTo-not-selectable/ );
  432. } );
  433. } );
  434. describe( 'getFirstRange()', () => {
  435. it( 'should return null if no ranges were added', () => {
  436. expect( selection.getFirstRange() ).to.be.null;
  437. } );
  438. it( 'should return a range which start position is before all other ranges\' start positions', () => {
  439. selection.setTo( [
  440. // This will not be the first range despite being added as first
  441. range2,
  442. // This should be the first range.
  443. range1,
  444. // A random range that is not first.
  445. range3
  446. ] );
  447. const range = selection.getFirstRange();
  448. expect( range.start.path ).to.deep.equal( [ 1 ] );
  449. expect( range.end.path ).to.deep.equal( [ 4 ] );
  450. } );
  451. } );
  452. describe( 'getFirstPosition()', () => {
  453. it( 'should return null if no ranges were added', () => {
  454. expect( selection.getFirstPosition() ).to.be.null;
  455. } );
  456. it( 'should return a position that is in selection and is before any other position from the selection', () => {
  457. selection.setTo( [
  458. // This will not be the first range despite being added as first
  459. range2,
  460. // This should be the first range.
  461. range1,
  462. // A random range that is not first.
  463. range3
  464. ] );
  465. const position = selection.getFirstPosition();
  466. expect( position.path ).to.deep.equal( [ 1 ] );
  467. } );
  468. } );
  469. describe( 'getLastRange()', () => {
  470. it( 'should return null if no ranges were added', () => {
  471. expect( selection.getLastRange() ).to.be.null;
  472. } );
  473. it( 'should return a range which start position is before all other ranges\' start positions', () => {
  474. selection.setTo( [ range3, range1, range2 ] );
  475. const range = selection.getLastRange();
  476. expect( range.start.path ).to.deep.equal( [ 6 ] );
  477. expect( range.end.path ).to.deep.equal( [ 7 ] );
  478. } );
  479. } );
  480. describe( 'getLastPosition()', () => {
  481. it( 'should return null if no ranges were added', () => {
  482. expect( selection.getLastPosition() ).to.be.null;
  483. } );
  484. it( 'should return a position that is in selection and is before any other position from the selection', () => {
  485. selection.setTo( [ range3, range1, range2 ] );
  486. const position = selection.getLastPosition();
  487. expect( position.path ).to.deep.equal( [ 7 ] );
  488. } );
  489. } );
  490. describe( 'isEqual()', () => {
  491. it( 'should return true if selections equal', () => {
  492. selection.setTo( [ range1, range2 ] );
  493. const otherSelection = new Selection( [ range1, range2 ] );
  494. expect( selection.isEqual( otherSelection ) ).to.be.true;
  495. } );
  496. it( 'should return true if backward selections equal', () => {
  497. selection.setTo( [ range1 ], true );
  498. const otherSelection = new Selection( [ range1 ], true );
  499. expect( selection.isEqual( otherSelection ) ).to.be.true;
  500. } );
  501. it( 'should return true if both selections have no ranges', () => {
  502. const otherSelection = new Selection();
  503. expect( selection.isEqual( otherSelection ) ).to.be.true;
  504. } );
  505. it( 'should return false if ranges count does not equal', () => {
  506. selection.setTo( [ range1, range2 ] );
  507. const otherSelection = new Selection( [ range2 ] );
  508. expect( selection.isEqual( otherSelection ) ).to.be.false;
  509. } );
  510. it( 'should return false if ranges (other than the last added range) do not equal', () => {
  511. selection.setTo( [ range1, range3 ] );
  512. const otherSelection = new Selection( [ range2, range3 ] );
  513. expect( selection.isEqual( otherSelection ) ).to.be.false;
  514. } );
  515. it( 'should return false if directions do not equal', () => {
  516. selection.setTo( range1 );
  517. const otherSelection = new Selection( [ range1 ], true );
  518. expect( selection.isEqual( otherSelection ) ).to.be.false;
  519. } );
  520. } );
  521. describe( 'setTo - used to collapse at start', () => {
  522. it( 'should collapse to start position and fire change event', () => {
  523. selection.setTo( [ range2, range1, range3 ] );
  524. const spy = sinon.spy();
  525. selection.on( 'change:range', spy );
  526. selection.setTo( selection.getFirstPosition() );
  527. expect( selection.rangeCount ).to.equal( 1 );
  528. expect( selection.isCollapsed ).to.be.true;
  529. expect( selection.getFirstPosition().isEqual( range1.start ) ).to.be.true;
  530. expect( spy.calledOnce ).to.be.true;
  531. } );
  532. it( 'should do nothing if selection was already collapsed', () => {
  533. selection.setTo( range1.start );
  534. const spy = sinon.spy( selection, 'fire' );
  535. selection.setTo( selection.getFirstPosition() );
  536. expect( spy.notCalled ).to.be.true;
  537. spy.restore();
  538. } );
  539. it( 'should do nothing if no ranges present', () => {
  540. const spy = sinon.spy( selection, 'fire' );
  541. selection.setTo( selection.getFirstPosition() );
  542. spy.restore();
  543. expect( spy.notCalled ).to.be.true;
  544. } );
  545. } );
  546. describe( 'setTo - used to collapse at end', () => {
  547. it( 'should collapse to start position and fire change:range event', () => {
  548. selection.setTo( [ range2, range3, range1 ] );
  549. const spy = sinon.spy();
  550. selection.on( 'change:range', spy );
  551. selection.setTo( selection.getLastPosition() );
  552. expect( selection.rangeCount ).to.equal( 1 );
  553. expect( selection.isCollapsed ).to.be.true;
  554. expect( selection.getLastPosition().isEqual( range3.end ) ).to.be.true;
  555. expect( spy.calledOnce ).to.be.true;
  556. } );
  557. it( 'should do nothing if selection was already collapsed', () => {
  558. selection.setTo( range1.start );
  559. const spy = sinon.spy( selection, 'fire' );
  560. selection.setTo( selection.getLastPosition() );
  561. expect( spy.notCalled ).to.be.true;
  562. spy.restore();
  563. } );
  564. it( 'should do nothing if selection has no ranges', () => {
  565. const spy = sinon.spy( selection, 'fire' );
  566. selection.setTo( selection.getLastPosition() );
  567. expect( spy.notCalled ).to.be.true;
  568. spy.restore();
  569. } );
  570. } );
  571. describe( 'createFromSelection()', () => {
  572. it( 'should return a Selection instance with same ranges and direction as given selection', () => {
  573. selection.setTo( [ liveRange, range ], true );
  574. const snapshot = Selection.createFromSelection( selection );
  575. expect( selection.isBackward ).to.equal( snapshot.isBackward );
  576. const selectionRanges = Array.from( selection.getRanges() );
  577. const snapshotRanges = Array.from( snapshot.getRanges() );
  578. expect( selectionRanges.length ).to.equal( snapshotRanges.length );
  579. for ( let i = 0; i < selectionRanges.length; i++ ) {
  580. expect( selectionRanges[ i ].isEqual( snapshotRanges[ i ] ) ).to.be.true;
  581. }
  582. } );
  583. } );
  584. describe( 'getSelectedElement()', () => {
  585. let schema;
  586. beforeEach( () => {
  587. schema = new Schema();
  588. schema.register( '$root' );
  589. schema.register( 'p', { allowIn: '$root' } );
  590. schema.register( '$text', { allowIn: 'p' } );
  591. } );
  592. it( 'should return selected element', () => {
  593. const { selection, model } = parse( '<p>foo</p>[<p>bar</p>]<p>baz</p>', schema );
  594. const p = model.getChild( 1 );
  595. expect( selection.getSelectedElement() ).to.equal( p );
  596. } );
  597. it( 'should return null if there is more than one range', () => {
  598. const { selection } = parse( '[<p>foo</p>][<p>bar</p>]<p>baz</p>', schema );
  599. expect( selection.getSelectedElement() ).to.be.null;
  600. } );
  601. it( 'should return null if there is no selection', () => {
  602. expect( selection.getSelectedElement() ).to.be.null;
  603. } );
  604. it( 'should return null if selection is not over single element #1', () => {
  605. const { selection } = parse( '<p>foo</p>[<p>bar</p><p>baz}</p>', schema );
  606. expect( selection.getSelectedElement() ).to.be.null;
  607. } );
  608. it( 'should return null if selection is not over single element #2', () => {
  609. const { selection } = parse( '<p>{bar}</p>', schema );
  610. expect( selection.getSelectedElement() ).to.be.null;
  611. } );
  612. } );
  613. describe( 'getSelectedBlocks()', () => {
  614. beforeEach( () => {
  615. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  616. model.schema.register( 'h', { inheritAllFrom: '$block' } );
  617. model.schema.register( 'blockquote' );
  618. model.schema.extend( 'blockquote', { allowIn: '$root' } );
  619. model.schema.extend( '$block', { allowIn: 'blockquote' } );
  620. model.schema.register( 'image', {
  621. allowIn: [ '$root', '$block' ]
  622. } );
  623. model.schema.extend( '$text', { allowIn: 'image' } );
  624. // Special block which can contain another blocks.
  625. model.schema.register( 'nestedBlock', { inheritAllFrom: '$block' } );
  626. model.schema.extend( 'nestedBlock', { allowIn: '$block' } );
  627. } );
  628. it( 'returns an iterator', () => {
  629. setData( model, '<p>a</p><p>[]b</p><p>c</p>' );
  630. expect( doc.selection.getSelectedBlocks().next ).to.be.a( 'function' );
  631. } );
  632. it( 'returns block for a collapsed selection', () => {
  633. setData( model, '<p>a</p><p>[]b</p><p>c</p>' );
  634. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  635. } );
  636. it( 'returns block for a collapsed selection (empty block)', () => {
  637. setData( model, '<p>a</p><p>[]</p><p>c</p>' );
  638. const blocks = Array.from( doc.selection.getSelectedBlocks() );
  639. expect( blocks ).to.have.length( 1 );
  640. expect( blocks[ 0 ].childCount ).to.equal( 0 );
  641. } );
  642. it( 'returns block for a non collapsed selection', () => {
  643. setData( model, '<p>a</p><p>[b]</p><p>c</p>' );
  644. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  645. } );
  646. it( 'returns two blocks for a non collapsed selection', () => {
  647. setData( model, '<p>a</p><h>[b</h><p>c]</p><p>d</p>' );
  648. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c' ] );
  649. } );
  650. it( 'returns two blocks for a non collapsed selection (starts at block end)', () => {
  651. setData( model, '<p>a</p><h>b[</h><p>c]</p><p>d</p>' );
  652. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c' ] );
  653. } );
  654. it( 'returns proper block for a multi-range selection', () => {
  655. setData( model, '<p>a</p><h>[b</h><p>c]</p><p>d</p><p>[e]</p>' );
  656. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c', 'e' ] );
  657. } );
  658. it( 'does not return a block twice if two ranges are anchored in it', () => {
  659. setData( model, '<p>[a]b[c]</p>' );
  660. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'abc' ] );
  661. } );
  662. it( 'returns only blocks', () => {
  663. setData( model, '<p>[a</p><image>b</image><p>c]</p>' );
  664. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'c' ] );
  665. } );
  666. it( 'gets deeper into the tree', () => {
  667. setData( model, '<p>[a</p><blockquote><p>b</p><p>c</p></blockquote><p>d]</p>' );
  668. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c', 'd' ] );
  669. } );
  670. it( 'gets deeper into the tree (end deeper)', () => {
  671. setData( model, '<p>[a</p><blockquote><p>b]</p><p>c</p></blockquote><p>d</p>' );
  672. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  673. } );
  674. it( 'gets deeper into the tree (start deeper)', () => {
  675. setData( model, '<p>a</p><blockquote><p>b</p><p>[c</p></blockquote><p>d]</p>' );
  676. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'c', 'd' ] );
  677. } );
  678. it( 'returns an empty array if none of the selected elements is a block', () => {
  679. setData( model, '<p>a</p><image>[a</image><image>b]</image><p>b</p>' );
  680. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  681. } );
  682. it( 'returns an empty array if the selected element is not a block', () => {
  683. setData( model, '<p>a</p><image>[]a</image><p>b</p>' );
  684. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  685. } );
  686. // Super edge case – should not happen (blocks should never be nested),
  687. // but since the code handles it already it's worth testing.
  688. it( 'returns only the lowest block if blocks are nested', () => {
  689. setData( model, '<nestedBlock>a<nestedBlock>[]b</nestedBlock></nestedBlock>' );
  690. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  691. } );
  692. // Like above but trickier.
  693. it( 'returns only the lowest block if blocks are nested', () => {
  694. setData(
  695. model,
  696. '<nestedBlock>a<nestedBlock>[b</nestedBlock></nestedBlock>' +
  697. '<nestedBlock>c<nestedBlock>d]</nestedBlock></nestedBlock>'
  698. );
  699. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'd' ] );
  700. } );
  701. it( 'returns nothing if directly in a root', () => {
  702. doc.createRoot( 'p', 'inlineOnlyRoot' );
  703. setData( model, 'a[b]c', { rootName: 'inlineOnlyRoot' } );
  704. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  705. } );
  706. describe( '#984', () => {
  707. it( 'does not return the last block if none of its content is selected', () => {
  708. setData( model, '<p>[a</p><p>b</p><p>]c</p>' );
  709. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  710. } );
  711. it( 'returns only the first block for a non collapsed selection if only end of selection is touching a block', () => {
  712. setData( model, '<p>a</p><h>b[</h><p>]c</p><p>d</p>' );
  713. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  714. } );
  715. it( 'does not return the last block if none of its content is selected (nested case)', () => {
  716. setData( model, '<p>[a</p><nestedBlock><nestedBlock>]b</nestedBlock></nestedBlock>' );
  717. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a' ] );
  718. } );
  719. // Like a super edge case, we can live with this behavior as I don't even know what we could expect here
  720. // since only the innermost block is considerd a block to return (so the <nB>b...</nB> needs to be ignored).
  721. it( 'does not return the last block if none of its content is selected (nested case, wrapper with a content)', () => {
  722. setData( model, '<p>[a</p><nestedBlock>b<nestedBlock>]c</nestedBlock></nestedBlock>' );
  723. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a' ] );
  724. } );
  725. it( 'returns the last block if at least one of its child nodes is selected', () => {
  726. setData( model, '<p>[a</p><p>b</p><p><image></image>]c</p>' );
  727. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
  728. } );
  729. // I needed these last 2 cases to justify the use of isTouching() instead of simple `offset == 0` check.
  730. it( 'returns the last block if at least one of its child nodes is selected (end in an inline element)', () => {
  731. setData( model, '<p>[a</p><p>b</p><p><image>x]</image>c</p>' );
  732. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
  733. } );
  734. it(
  735. 'does not return the last block if at least one of its child nodes is selected ' +
  736. '(end in an inline element, no content selected)',
  737. () => {
  738. setData( model, '<p>[a</p><p>b</p><p><image>]x</image>c</p>' );
  739. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  740. }
  741. );
  742. } );
  743. // Map all elements to data of its first child text node.
  744. function toText( elements ) {
  745. return Array.from( elements ).map( el => {
  746. return Array.from( el.getChildren() ).find( child => child.data ).data;
  747. } );
  748. }
  749. } );
  750. describe( 'attributes interface', () => {
  751. let rangeInFullP;
  752. beforeEach( () => {
  753. root.insertChildren( 0, [
  754. new Element( 'p', [], new Text( 'foobar' ) ),
  755. new Element( 'p', [], [] )
  756. ] );
  757. rangeInFullP = new Range( new Position( root, [ 0, 4 ] ), new Position( root, [ 0, 4 ] ) );
  758. } );
  759. describe( 'setAttribute()', () => {
  760. it( 'should set given attribute on the selection', () => {
  761. selection.setTo( [ rangeInFullP ] );
  762. selection.setAttribute( 'foo', 'bar' );
  763. expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  764. } );
  765. it( 'should fire change:attribute event with correct parameters', () => {
  766. selection.on( 'change:attribute', ( evt, data ) => {
  767. expect( data.directChange ).to.be.true;
  768. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  769. } );
  770. selection.setAttribute( 'foo', 'bar' );
  771. } );
  772. it( 'should not fire change:attribute event if attribute with same key and value was already set', () => {
  773. selection.setAttribute( 'foo', 'bar' );
  774. const spy = sinon.spy();
  775. selection.on( 'change:attribute', spy );
  776. selection.setAttribute( 'foo', 'bar' );
  777. expect( spy.called ).to.be.false;
  778. } );
  779. } );
  780. describe( 'getAttribute()', () => {
  781. it( 'should return undefined if element does not contain given attribute', () => {
  782. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  783. } );
  784. } );
  785. describe( 'getAttributes()', () => {
  786. it( 'should return an iterator that iterates over all attributes set on selection', () => {
  787. selection.setTo( [ rangeInFullP ] );
  788. selection.setAttribute( 'foo', 'bar' );
  789. selection.setAttribute( 'abc', 'xyz' );
  790. const attrs = Array.from( selection.getAttributes() );
  791. expect( attrs ).to.deep.equal( [ [ 'foo', 'bar' ], [ 'abc', 'xyz' ] ] );
  792. } );
  793. } );
  794. describe( 'getAttributeKeys()', () => {
  795. it( 'should return iterator that iterates over all attribute keys set on selection', () => {
  796. selection.setTo( [ rangeInFullP ] );
  797. selection.setAttribute( 'foo', 'bar' );
  798. selection.setAttribute( 'abc', 'xyz' );
  799. const attrs = Array.from( selection.getAttributeKeys() );
  800. expect( attrs ).to.deep.equal( [ 'foo', 'abc' ] );
  801. } );
  802. } );
  803. describe( 'hasAttribute()', () => {
  804. it( 'should return true if element contains attribute with given key', () => {
  805. selection.setTo( [ rangeInFullP ] );
  806. selection.setAttribute( 'foo', 'bar' );
  807. expect( selection.hasAttribute( 'foo' ) ).to.be.true;
  808. } );
  809. it( 'should return false if element does not contain attribute with given key', () => {
  810. expect( selection.hasAttribute( 'abc' ) ).to.be.false;
  811. } );
  812. } );
  813. describe( 'clearAttributes()', () => {
  814. it( 'should remove all attributes from the element', () => {
  815. selection.setTo( [ rangeInFullP ] );
  816. selection.setAttribute( 'foo', 'bar' );
  817. selection.setAttribute( 'abc', 'xyz' );
  818. selection.clearAttributes();
  819. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  820. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  821. } );
  822. it( 'should fire change:attribute event with correct parameters', () => {
  823. selection.setAttribute( 'foo', 'bar' );
  824. selection.on( 'change:attribute', ( evt, data ) => {
  825. expect( data.directChange ).to.be.true;
  826. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  827. } );
  828. selection.clearAttributes();
  829. } );
  830. it( 'should not fire change:attribute event if there were no attributes', () => {
  831. const spy = sinon.spy();
  832. selection.on( 'change:attribute', spy );
  833. selection.clearAttributes();
  834. expect( spy.called ).to.be.false;
  835. } );
  836. } );
  837. describe( 'removeAttribute()', () => {
  838. it( 'should remove attribute', () => {
  839. selection.setTo( [ rangeInFullP ] );
  840. selection.setAttribute( 'foo', 'bar' );
  841. selection.removeAttribute( 'foo' );
  842. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  843. } );
  844. it( 'should fire change:attribute event with correct parameters', () => {
  845. selection.setAttribute( 'foo', 'bar' );
  846. selection.on( 'change:attribute', ( evt, data ) => {
  847. expect( data.directChange ).to.be.true;
  848. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  849. } );
  850. selection.removeAttribute( 'foo' );
  851. } );
  852. it( 'should not fire change:attribute event if such attribute did not exist', () => {
  853. const spy = sinon.spy();
  854. selection.on( 'change:attribute', spy );
  855. selection.removeAttribute( 'foo' );
  856. expect( spy.called ).to.be.false;
  857. } );
  858. } );
  859. } );
  860. describe( 'containsEntireContent()', () => {
  861. beforeEach( () => {
  862. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  863. model.schema.extend( 'p', { allowIn: '$root' } );
  864. } );
  865. it( 'returns true if the entire content in $root is selected', () => {
  866. setData( model, '<p>[Foo</p><p>Bom</p><p>Bar]</p>' );
  867. expect( doc.selection.containsEntireContent() ).to.equal( true );
  868. } );
  869. it( 'returns false when only a fragment of the content in $root is selected', () => {
  870. setData( model, '<p>Fo[o</p><p>Bom</p><p>Bar]</p>' );
  871. expect( doc.selection.containsEntireContent() ).to.equal( false );
  872. } );
  873. it( 'returns true if the entire content in specified element is selected', () => {
  874. setData( model, '<p>Foo</p><p>[Bom]</p><p>Bar</p>' );
  875. const root = doc.getRoot();
  876. const secondParagraph = root.getNodeByPath( [ 1 ] );
  877. expect( doc.selection.containsEntireContent( secondParagraph ) ).to.equal( true );
  878. } );
  879. it( 'returns false if the entire content in specified element is not selected', () => {
  880. setData( model, '<p>Foo</p><p>[Bom</p><p>B]ar</p>' );
  881. const root = doc.getRoot();
  882. const secondParagraph = root.getNodeByPath( [ 1 ] );
  883. expect( doc.selection.containsEntireContent( secondParagraph ) ).to.equal( false );
  884. } );
  885. it( 'returns false when the entire content except an empty element is selected', () => {
  886. model.schema.register( 'img', {
  887. allowIn: 'p'
  888. } );
  889. setData( model, '<p><img></img>[Foo]</p>' );
  890. expect( doc.selection.containsEntireContent() ).to.equal( false );
  891. } );
  892. it( 'returns true if the content is empty', () => {
  893. setData( model, '[]' );
  894. expect( doc.selection.containsEntireContent() ).to.equal( true );
  895. } );
  896. it( 'returns false if empty selection is at the end of non-empty content', () => {
  897. setData( model, '<p>Foo bar bom.</p>[]' );
  898. expect( doc.selection.containsEntireContent() ).to.equal( false );
  899. } );
  900. } );
  901. } );