selection.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  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()', () => {
  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()', () => {
  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 - set 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. } );
  429. describe( 'getFirstRange()', () => {
  430. it( 'should return null if no ranges were added', () => {
  431. expect( selection.getFirstRange() ).to.be.null;
  432. } );
  433. it( 'should return a range which start position is before all other ranges\' start positions', () => {
  434. selection.setTo( [
  435. // This will not be the first range despite being added as first
  436. range2,
  437. // This should be the first range.
  438. range1,
  439. // A random range that is not first.
  440. range3
  441. ] );
  442. const range = selection.getFirstRange();
  443. expect( range.start.path ).to.deep.equal( [ 1 ] );
  444. expect( range.end.path ).to.deep.equal( [ 4 ] );
  445. } );
  446. } );
  447. describe( 'getFirstPosition()', () => {
  448. it( 'should return null if no ranges were added', () => {
  449. expect( selection.getFirstPosition() ).to.be.null;
  450. } );
  451. it( 'should return a position that is in selection and is before any other position from the selection', () => {
  452. selection.setTo( [
  453. // This will not be the first range despite being added as first
  454. range2,
  455. // This should be the first range.
  456. range1,
  457. // A random range that is not first.
  458. range3
  459. ] );
  460. const position = selection.getFirstPosition();
  461. expect( position.path ).to.deep.equal( [ 1 ] );
  462. } );
  463. } );
  464. describe( 'getLastRange()', () => {
  465. it( 'should return null if no ranges were added', () => {
  466. expect( selection.getLastRange() ).to.be.null;
  467. } );
  468. it( 'should return a range which start position is before all other ranges\' start positions', () => {
  469. selection.setTo( [ range3, range1, range2 ] );
  470. const range = selection.getLastRange();
  471. expect( range.start.path ).to.deep.equal( [ 6 ] );
  472. expect( range.end.path ).to.deep.equal( [ 7 ] );
  473. } );
  474. } );
  475. describe( 'getLastPosition()', () => {
  476. it( 'should return null if no ranges were added', () => {
  477. expect( selection.getLastPosition() ).to.be.null;
  478. } );
  479. it( 'should return a position that is in selection and is before any other position from the selection', () => {
  480. selection.setTo( [ range3, range1, range2 ] );
  481. const position = selection.getLastPosition();
  482. expect( position.path ).to.deep.equal( [ 7 ] );
  483. } );
  484. } );
  485. describe( 'isEqual()', () => {
  486. it( 'should return true if selections equal', () => {
  487. selection.setTo( [ range1, range2 ] );
  488. const otherSelection = new Selection( [ range1, range2 ] );
  489. expect( selection.isEqual( otherSelection ) ).to.be.true;
  490. } );
  491. it( 'should return true if backward selections equal', () => {
  492. selection.setTo( [ range1 ], true );
  493. const otherSelection = new Selection( [ range1 ], true );
  494. expect( selection.isEqual( otherSelection ) ).to.be.true;
  495. } );
  496. it( 'should return true if both selections have no ranges', () => {
  497. const otherSelection = new Selection();
  498. expect( selection.isEqual( otherSelection ) ).to.be.true;
  499. } );
  500. it( 'should return false if ranges count does not equal', () => {
  501. selection.setTo( [ range1, range2 ] );
  502. const otherSelection = new Selection( [ range2 ] );
  503. expect( selection.isEqual( otherSelection ) ).to.be.false;
  504. } );
  505. it( 'should return false if ranges (other than the last added range) do not equal', () => {
  506. selection.setTo( [ range1, range3 ] );
  507. const otherSelection = new Selection( [ range2, range3 ] );
  508. expect( selection.isEqual( otherSelection ) ).to.be.false;
  509. } );
  510. it( 'should return false if directions do not equal', () => {
  511. selection.setTo( range1 );
  512. const otherSelection = new Selection( [ range1 ], true );
  513. expect( selection.isEqual( otherSelection ) ).to.be.false;
  514. } );
  515. } );
  516. describe( 'setTo - used to collapse at start', () => {
  517. it( 'should collapse to start position and fire change event', () => {
  518. selection.setTo( [ range2, range1, range3 ] );
  519. const spy = sinon.spy();
  520. selection.on( 'change:range', spy );
  521. selection.setTo( selection.getFirstPosition() );
  522. expect( selection.rangeCount ).to.equal( 1 );
  523. expect( selection.isCollapsed ).to.be.true;
  524. expect( selection.getFirstPosition().isEqual( range1.start ) ).to.be.true;
  525. expect( spy.calledOnce ).to.be.true;
  526. } );
  527. it( 'should do nothing if selection was already collapsed', () => {
  528. selection.setTo( range1.start );
  529. const spy = sinon.spy( selection, 'fire' );
  530. selection.setTo( selection.getFirstPosition() );
  531. expect( spy.notCalled ).to.be.true;
  532. spy.restore();
  533. } );
  534. it( 'should do nothing if no ranges present', () => {
  535. const spy = sinon.spy( selection, 'fire' );
  536. selection.setTo( selection.getFirstPosition() );
  537. spy.restore();
  538. expect( spy.notCalled ).to.be.true;
  539. } );
  540. } );
  541. describe( 'setTo - used to collapse at end', () => {
  542. it( 'should collapse to start position and fire change:range event', () => {
  543. selection.setTo( [ range2, range3, range1 ] );
  544. const spy = sinon.spy();
  545. selection.on( 'change:range', spy );
  546. selection.setTo( selection.getLastPosition() );
  547. expect( selection.rangeCount ).to.equal( 1 );
  548. expect( selection.isCollapsed ).to.be.true;
  549. expect( selection.getLastPosition().isEqual( range3.end ) ).to.be.true;
  550. expect( spy.calledOnce ).to.be.true;
  551. } );
  552. it( 'should do nothing if selection was already collapsed', () => {
  553. selection.setTo( range1.start );
  554. const spy = sinon.spy( selection, 'fire' );
  555. selection.setTo( selection.getLastPosition() );
  556. expect( spy.notCalled ).to.be.true;
  557. spy.restore();
  558. } );
  559. it( 'should do nothing if selection has no ranges', () => {
  560. const spy = sinon.spy( selection, 'fire' );
  561. selection.setTo( selection.getLastPosition() );
  562. expect( spy.notCalled ).to.be.true;
  563. spy.restore();
  564. } );
  565. } );
  566. describe( 'createFromSelection()', () => {
  567. it( 'should return a Selection instance with same ranges and direction as given selection', () => {
  568. selection.setTo( [ liveRange, range ], true );
  569. const snapshot = Selection.createFromSelection( selection );
  570. expect( selection.isBackward ).to.equal( snapshot.isBackward );
  571. const selectionRanges = Array.from( selection.getRanges() );
  572. const snapshotRanges = Array.from( snapshot.getRanges() );
  573. expect( selectionRanges.length ).to.equal( snapshotRanges.length );
  574. for ( let i = 0; i < selectionRanges.length; i++ ) {
  575. expect( selectionRanges[ i ].isEqual( snapshotRanges[ i ] ) ).to.be.true;
  576. }
  577. } );
  578. } );
  579. describe( 'getSelectedElement()', () => {
  580. let schema;
  581. beforeEach( () => {
  582. schema = new Schema();
  583. schema.register( '$root' );
  584. schema.register( 'p', { allowIn: '$root' } );
  585. schema.register( '$text', { allowIn: 'p' } );
  586. } );
  587. it( 'should return selected element', () => {
  588. const { selection, model } = parse( '<p>foo</p>[<p>bar</p>]<p>baz</p>', schema );
  589. const p = model.getChild( 1 );
  590. expect( selection.getSelectedElement() ).to.equal( p );
  591. } );
  592. it( 'should return null if there is more than one range', () => {
  593. const { selection } = parse( '[<p>foo</p>][<p>bar</p>]<p>baz</p>', schema );
  594. expect( selection.getSelectedElement() ).to.be.null;
  595. } );
  596. it( 'should return null if there is no selection', () => {
  597. expect( selection.getSelectedElement() ).to.be.null;
  598. } );
  599. it( 'should return null if selection is not over single element #1', () => {
  600. const { selection } = parse( '<p>foo</p>[<p>bar</p><p>baz}</p>', schema );
  601. expect( selection.getSelectedElement() ).to.be.null;
  602. } );
  603. it( 'should return null if selection is not over single element #2', () => {
  604. const { selection } = parse( '<p>{bar}</p>', schema );
  605. expect( selection.getSelectedElement() ).to.be.null;
  606. } );
  607. } );
  608. describe( 'getSelectedBlocks()', () => {
  609. beforeEach( () => {
  610. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  611. model.schema.register( 'h', { inheritAllFrom: '$block' } );
  612. model.schema.register( 'blockquote' );
  613. model.schema.extend( 'blockquote', { allowIn: '$root' } );
  614. model.schema.extend( '$block', { allowIn: 'blockquote' } );
  615. model.schema.register( 'image', {
  616. allowIn: [ '$root', '$block' ]
  617. } );
  618. model.schema.extend( '$text', { allowIn: 'image' } );
  619. // Special block which can contain another blocks.
  620. model.schema.register( 'nestedBlock', { inheritAllFrom: '$block' } );
  621. model.schema.extend( 'nestedBlock', { allowIn: '$block' } );
  622. } );
  623. it( 'returns an iterator', () => {
  624. setData( model, '<p>a</p><p>[]b</p><p>c</p>' );
  625. expect( doc.selection.getSelectedBlocks().next ).to.be.a( 'function' );
  626. } );
  627. it( 'returns block for a collapsed selection', () => {
  628. setData( model, '<p>a</p><p>[]b</p><p>c</p>' );
  629. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  630. } );
  631. it( 'returns block for a collapsed selection (empty block)', () => {
  632. setData( model, '<p>a</p><p>[]</p><p>c</p>' );
  633. const blocks = Array.from( doc.selection.getSelectedBlocks() );
  634. expect( blocks ).to.have.length( 1 );
  635. expect( blocks[ 0 ].childCount ).to.equal( 0 );
  636. } );
  637. it( 'returns block for a non collapsed selection', () => {
  638. setData( model, '<p>a</p><p>[b]</p><p>c</p>' );
  639. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  640. } );
  641. it( 'returns two blocks for a non collapsed selection', () => {
  642. setData( model, '<p>a</p><h>[b</h><p>c]</p><p>d</p>' );
  643. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c' ] );
  644. } );
  645. it( 'returns two blocks for a non collapsed selection (starts at block end)', () => {
  646. setData( model, '<p>a</p><h>b[</h><p>c]</p><p>d</p>' );
  647. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c' ] );
  648. } );
  649. it( 'returns proper block for a multi-range selection', () => {
  650. setData( model, '<p>a</p><h>[b</h><p>c]</p><p>d</p><p>[e]</p>' );
  651. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'c', 'e' ] );
  652. } );
  653. it( 'does not return a block twice if two ranges are anchored in it', () => {
  654. setData( model, '<p>[a]b[c]</p>' );
  655. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'abc' ] );
  656. } );
  657. it( 'returns only blocks', () => {
  658. setData( model, '<p>[a</p><image>b</image><p>c]</p>' );
  659. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'c' ] );
  660. } );
  661. it( 'gets deeper into the tree', () => {
  662. setData( model, '<p>[a</p><blockquote><p>b</p><p>c</p></blockquote><p>d]</p>' );
  663. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c', 'd' ] );
  664. } );
  665. it( 'gets deeper into the tree (end deeper)', () => {
  666. setData( model, '<p>[a</p><blockquote><p>b]</p><p>c</p></blockquote><p>d</p>' );
  667. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  668. } );
  669. it( 'gets deeper into the tree (start deeper)', () => {
  670. setData( model, '<p>a</p><blockquote><p>b</p><p>[c</p></blockquote><p>d]</p>' );
  671. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'c', 'd' ] );
  672. } );
  673. it( 'returns an empty array if none of the selected elements is a block', () => {
  674. setData( model, '<p>a</p><image>[a</image><image>b]</image><p>b</p>' );
  675. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  676. } );
  677. it( 'returns an empty array if the selected element is not a block', () => {
  678. setData( model, '<p>a</p><image>[]a</image><p>b</p>' );
  679. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  680. } );
  681. // Super edge case – should not happen (blocks should never be nested),
  682. // but since the code handles it already it's worth testing.
  683. it( 'returns only the lowest block if blocks are nested', () => {
  684. setData( model, '<nestedBlock>a<nestedBlock>[]b</nestedBlock></nestedBlock>' );
  685. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  686. } );
  687. // Like above but trickier.
  688. it( 'returns only the lowest block if blocks are nested', () => {
  689. setData(
  690. model,
  691. '<nestedBlock>a<nestedBlock>[b</nestedBlock></nestedBlock>' +
  692. '<nestedBlock>c<nestedBlock>d]</nestedBlock></nestedBlock>'
  693. );
  694. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b', 'd' ] );
  695. } );
  696. it( 'returns nothing if directly in a root', () => {
  697. doc.createRoot( 'p', 'inlineOnlyRoot' );
  698. setData( model, 'a[b]c', { rootName: 'inlineOnlyRoot' } );
  699. expect( toText( doc.selection.getSelectedBlocks() ) ).to.be.empty;
  700. } );
  701. describe( '#984', () => {
  702. it( 'does not return the last block if none of its content is selected', () => {
  703. setData( model, '<p>[a</p><p>b</p><p>]c</p>' );
  704. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  705. } );
  706. it( 'returns only the first block for a non collapsed selection if only end of selection is touching a block', () => {
  707. setData( model, '<p>a</p><h>b[</h><p>]c</p><p>d</p>' );
  708. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'b' ] );
  709. } );
  710. it( 'does not return the last block if none of its content is selected (nested case)', () => {
  711. setData( model, '<p>[a</p><nestedBlock><nestedBlock>]b</nestedBlock></nestedBlock>' );
  712. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a' ] );
  713. } );
  714. // Like a super edge case, we can live with this behavior as I don't even know what we could expect here
  715. // since only the innermost block is considerd a block to return (so the <nB>b...</nB> needs to be ignored).
  716. it( 'does not return the last block if none of its content is selected (nested case, wrapper with a content)', () => {
  717. setData( model, '<p>[a</p><nestedBlock>b<nestedBlock>]c</nestedBlock></nestedBlock>' );
  718. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a' ] );
  719. } );
  720. it( 'returns the last block if at least one of its child nodes is selected', () => {
  721. setData( model, '<p>[a</p><p>b</p><p><image></image>]c</p>' );
  722. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
  723. } );
  724. // I needed these last 2 cases to justify the use of isTouching() instead of simple `offset == 0` check.
  725. it( 'returns the last block if at least one of its child nodes is selected (end in an inline element)', () => {
  726. setData( model, '<p>[a</p><p>b</p><p><image>x]</image>c</p>' );
  727. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
  728. } );
  729. it(
  730. 'does not return the last block if at least one of its child nodes is selected ' +
  731. '(end in an inline element, no content selected)',
  732. () => {
  733. setData( model, '<p>[a</p><p>b</p><p><image>]x</image>c</p>' );
  734. expect( toText( doc.selection.getSelectedBlocks() ) ).to.deep.equal( [ 'a', 'b' ] );
  735. }
  736. );
  737. } );
  738. // Map all elements to data of its first child text node.
  739. function toText( elements ) {
  740. return Array.from( elements ).map( el => {
  741. return Array.from( el.getChildren() ).find( child => child.data ).data;
  742. } );
  743. }
  744. } );
  745. describe( 'attributes interface', () => {
  746. let rangeInFullP;
  747. beforeEach( () => {
  748. root.insertChildren( 0, [
  749. new Element( 'p', [], new Text( 'foobar' ) ),
  750. new Element( 'p', [], [] )
  751. ] );
  752. rangeInFullP = new Range( new Position( root, [ 0, 4 ] ), new Position( root, [ 0, 4 ] ) );
  753. } );
  754. describe( 'setAttribute()', () => {
  755. it( 'should set given attribute on the selection', () => {
  756. selection.setTo( [ rangeInFullP ] );
  757. selection.setAttribute( 'foo', 'bar' );
  758. expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  759. } );
  760. it( 'should fire change:attribute event with correct parameters', () => {
  761. selection.on( 'change:attribute', ( evt, data ) => {
  762. expect( data.directChange ).to.be.true;
  763. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  764. } );
  765. selection.setAttribute( 'foo', 'bar' );
  766. } );
  767. it( 'should not fire change:attribute event if attribute with same key and value was already set', () => {
  768. selection.setAttribute( 'foo', 'bar' );
  769. const spy = sinon.spy();
  770. selection.on( 'change:attribute', spy );
  771. selection.setAttribute( 'foo', 'bar' );
  772. expect( spy.called ).to.be.false;
  773. } );
  774. } );
  775. describe( 'getAttribute()', () => {
  776. it( 'should return undefined if element does not contain given attribute', () => {
  777. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  778. } );
  779. } );
  780. describe( 'getAttributes()', () => {
  781. it( 'should return an iterator that iterates over all attributes set on selection', () => {
  782. selection.setTo( [ rangeInFullP ] );
  783. selection.setAttribute( 'foo', 'bar' );
  784. selection.setAttribute( 'abc', 'xyz' );
  785. const attrs = Array.from( selection.getAttributes() );
  786. expect( attrs ).to.deep.equal( [ [ 'foo', 'bar' ], [ 'abc', 'xyz' ] ] );
  787. } );
  788. } );
  789. describe( 'getAttributeKeys()', () => {
  790. it( 'should return iterator that iterates over all attribute keys set on selection', () => {
  791. selection.setTo( [ rangeInFullP ] );
  792. selection.setAttribute( 'foo', 'bar' );
  793. selection.setAttribute( 'abc', 'xyz' );
  794. const attrs = Array.from( selection.getAttributeKeys() );
  795. expect( attrs ).to.deep.equal( [ 'foo', 'abc' ] );
  796. } );
  797. } );
  798. describe( 'hasAttribute()', () => {
  799. it( 'should return true if element contains attribute with given key', () => {
  800. selection.setTo( [ rangeInFullP ] );
  801. selection.setAttribute( 'foo', 'bar' );
  802. expect( selection.hasAttribute( 'foo' ) ).to.be.true;
  803. } );
  804. it( 'should return false if element does not contain attribute with given key', () => {
  805. expect( selection.hasAttribute( 'abc' ) ).to.be.false;
  806. } );
  807. } );
  808. describe( 'clearAttributes()', () => {
  809. it( 'should remove all attributes from the element', () => {
  810. selection.setTo( [ rangeInFullP ] );
  811. selection.setAttribute( 'foo', 'bar' );
  812. selection.setAttribute( 'abc', 'xyz' );
  813. selection.clearAttributes();
  814. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  815. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  816. } );
  817. it( 'should fire change:attribute event with correct parameters', () => {
  818. selection.setAttribute( 'foo', 'bar' );
  819. selection.on( 'change:attribute', ( evt, data ) => {
  820. expect( data.directChange ).to.be.true;
  821. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  822. } );
  823. selection.clearAttributes();
  824. } );
  825. it( 'should not fire change:attribute event if there were no attributes', () => {
  826. const spy = sinon.spy();
  827. selection.on( 'change:attribute', spy );
  828. selection.clearAttributes();
  829. expect( spy.called ).to.be.false;
  830. } );
  831. } );
  832. describe( 'removeAttribute()', () => {
  833. it( 'should remove attribute', () => {
  834. selection.setTo( [ rangeInFullP ] );
  835. selection.setAttribute( 'foo', 'bar' );
  836. selection.removeAttribute( 'foo' );
  837. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  838. } );
  839. it( 'should fire change:attribute event with correct parameters', () => {
  840. selection.setAttribute( 'foo', 'bar' );
  841. selection.on( 'change:attribute', ( evt, data ) => {
  842. expect( data.directChange ).to.be.true;
  843. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  844. } );
  845. selection.removeAttribute( 'foo' );
  846. } );
  847. it( 'should not fire change:attribute event if such attribute did not exist', () => {
  848. const spy = sinon.spy();
  849. selection.on( 'change:attribute', spy );
  850. selection.removeAttribute( 'foo' );
  851. expect( spy.called ).to.be.false;
  852. } );
  853. } );
  854. } );
  855. describe( 'containsEntireContent()', () => {
  856. beforeEach( () => {
  857. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  858. model.schema.extend( 'p', { allowIn: '$root' } );
  859. } );
  860. it( 'returns true if the entire content in $root is selected', () => {
  861. setData( model, '<p>[Foo</p><p>Bom</p><p>Bar]</p>' );
  862. expect( doc.selection.containsEntireContent() ).to.equal( true );
  863. } );
  864. it( 'returns false when only a fragment of the content in $root is selected', () => {
  865. setData( model, '<p>Fo[o</p><p>Bom</p><p>Bar]</p>' );
  866. expect( doc.selection.containsEntireContent() ).to.equal( false );
  867. } );
  868. it( 'returns true if the entire content in specified element is selected', () => {
  869. setData( model, '<p>Foo</p><p>[Bom]</p><p>Bar</p>' );
  870. const root = doc.getRoot();
  871. const secondParagraph = root.getNodeByPath( [ 1 ] );
  872. expect( doc.selection.containsEntireContent( secondParagraph ) ).to.equal( true );
  873. } );
  874. it( 'returns false if the entire content in specified element is not selected', () => {
  875. setData( model, '<p>Foo</p><p>[Bom</p><p>B]ar</p>' );
  876. const root = doc.getRoot();
  877. const secondParagraph = root.getNodeByPath( [ 1 ] );
  878. expect( doc.selection.containsEntireContent( secondParagraph ) ).to.equal( false );
  879. } );
  880. it( 'returns false when the entire content except an empty element is selected', () => {
  881. model.schema.register( 'img', {
  882. allowIn: 'p'
  883. } );
  884. setData( model, '<p><img></img>[Foo]</p>' );
  885. expect( doc.selection.containsEntireContent() ).to.equal( false );
  886. } );
  887. it( 'returns true if the content is empty', () => {
  888. setData( model, '[]' );
  889. expect( doc.selection.containsEntireContent() ).to.equal( true );
  890. } );
  891. it( 'returns false if empty selection is at the end of non-empty content', () => {
  892. setData( model, '<p>Foo bar bom.</p>[]' );
  893. expect( doc.selection.containsEntireContent() ).to.equal( false );
  894. } );
  895. } );
  896. } );