documentselection.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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 Batch from '../../src/model/batch';
  7. import Element from '../../src/model/element';
  8. import Text from '../../src/model/text';
  9. import Range from '../../src/model/range';
  10. import Position from '../../src/model/position';
  11. import LiveRange from '../../src/model/liverange';
  12. import DocumentSelection from '../../src/model/documentselection';
  13. import InsertOperation from '../../src/model/operation/insertoperation';
  14. import MoveOperation from '../../src/model/operation/moveoperation';
  15. import RemoveOperation from '../../src/model/operation/removeoperation';
  16. import AttributeOperation from '../../src/model/operation/attributeoperation';
  17. import SplitDelta from '../../src/model/delta/splitdelta';
  18. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  19. import count from '@ckeditor/ckeditor5-utils/src/count';
  20. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  21. import { wrapInDelta } from '../../tests/model/_utils/utils';
  22. import { setData, getData } from '../../src/dev-utils/model';
  23. import log from '@ckeditor/ckeditor5-utils/src/log';
  24. testUtils.createSinonSandbox();
  25. describe( 'DocumentSelection', () => {
  26. let model, doc, root, selection, liveRange, range;
  27. const fooStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'foo' );
  28. const abcStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'abc' );
  29. beforeEach( () => {
  30. model = new Model();
  31. doc = model.document;
  32. root = doc.createRoot();
  33. root.appendChildren( [
  34. new Element( 'p' ),
  35. new Element( 'p' ),
  36. new Element( 'p', [], new Text( 'foobar' ) ),
  37. new Element( 'p' ),
  38. new Element( 'p' ),
  39. new Element( 'p' ),
  40. new Element( 'p', [], new Text( 'foobar' ) )
  41. ] );
  42. selection = doc.selection;
  43. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  44. model.schema.register( 'widget', {
  45. isObject: true
  46. } );
  47. liveRange = new LiveRange( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
  48. range = new Range( new Position( root, [ 2 ] ), new Position( root, [ 2, 2 ] ) );
  49. } );
  50. afterEach( () => {
  51. model.destroy();
  52. liveRange.detach();
  53. } );
  54. describe( 'default range', () => {
  55. it( 'should go to the first editable element', () => {
  56. const ranges = Array.from( selection.getRanges() );
  57. expect( ranges.length ).to.equal( 1 );
  58. expect( selection.anchor.isEqual( new Position( root, [ 0, 0 ] ) ) ).to.be.true;
  59. expect( selection.focus.isEqual( new Position( root, [ 0, 0 ] ) ) ).to.be.true;
  60. expect( selection ).to.have.property( 'isBackward', false );
  61. } );
  62. it( 'should be set to the beginning of the doc if there is no editable element', () => {
  63. model = new Model();
  64. doc = model.document;
  65. root = doc.createRoot();
  66. root.insertChildren( 0, new Text( 'foobar' ) );
  67. selection = doc.selection;
  68. const ranges = Array.from( selection.getRanges() );
  69. expect( ranges.length ).to.equal( 1 );
  70. expect( selection.anchor.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
  71. expect( selection.focus.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true;
  72. expect( selection ).to.have.property( 'isBackward', false );
  73. expect( count( selection.getAttributes() ) ).to.equal( 0 );
  74. } );
  75. it( 'should skip element when you can not put selection', () => {
  76. model = new Model();
  77. doc = model.document;
  78. root = doc.createRoot();
  79. root.insertChildren( 0, [
  80. new Element( 'img' ),
  81. new Element( 'p', [], new Text( 'foobar' ) )
  82. ] );
  83. model.schema.register( 'img' );
  84. model.schema.register( 'p', { inheritAllFrom: '$block' } );
  85. selection = doc.selection;
  86. const ranges = Array.from( selection.getRanges() );
  87. expect( ranges.length ).to.equal( 1 );
  88. expect( selection.anchor.isEqual( new Position( root, [ 1, 0 ] ) ) ).to.be.true;
  89. expect( selection.focus.isEqual( new Position( root, [ 1, 0 ] ) ) ).to.be.true;
  90. expect( selection ).to.have.property( 'isBackward', false );
  91. expect( count( selection.getAttributes() ) ).to.equal( 0 );
  92. } );
  93. } );
  94. describe( 'isCollapsed', () => {
  95. it( 'should be true for the default range (in text position)', () => {
  96. expect( selection.isCollapsed ).to.be.true;
  97. } );
  98. it( 'should be false for the default range (object selection) ', () => {
  99. root.insertChildren( 0, new Element( 'widget' ) );
  100. expect( selection.isCollapsed ).to.be.false;
  101. } );
  102. it( 'should back off to the default algorithm if selection has ranges', () => {
  103. selection._setTo( range );
  104. expect( selection.isCollapsed ).to.be.false;
  105. } );
  106. } );
  107. describe( 'anchor', () => {
  108. it( 'should equal the default range\'s start (in text position)', () => {
  109. const expectedPos = new Position( root, [ 0, 0 ] );
  110. expect( selection.anchor.isEqual( expectedPos ) ).to.be.true;
  111. } );
  112. it( 'should equal the default range\'s start (object selection)', () => {
  113. root.insertChildren( 0, new Element( 'widget' ) );
  114. const expectedPos = new Position( root, [ 0 ] );
  115. expect( selection.anchor.isEqual( expectedPos ) ).to.be.true;
  116. } );
  117. it( 'should back off to the default algorithm if selection has ranges', () => {
  118. selection._setTo( range );
  119. expect( selection.anchor.isEqual( range.start ) ).to.be.true;
  120. } );
  121. } );
  122. describe( 'focus', () => {
  123. it( 'should equal the default range\'s end (in text position)', () => {
  124. const expectedPos = new Position( root, [ 0, 0 ] );
  125. expect( selection.focus.isEqual( expectedPos ) ).to.be.true;
  126. } );
  127. it( 'should equal the default range\'s end (object selection)', () => {
  128. root.insertChildren( 0, new Element( 'widget' ) );
  129. const expectedPos = new Position( root, [ 1 ] );
  130. expect( selection.focus.isEqual( expectedPos ) ).to.be.true;
  131. expect( selection.focus.isEqual( selection.getFirstRange().end ) ).to.be.true;
  132. } );
  133. it( 'should back off to the default algorithm if selection has ranges', () => {
  134. selection._setTo( range );
  135. expect( selection.focus.isEqual( range.end ) ).to.be.true;
  136. } );
  137. } );
  138. describe( 'rangeCount', () => {
  139. it( 'should return proper range count', () => {
  140. expect( selection.rangeCount ).to.equal( 1 );
  141. selection._setTo( new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) );
  142. expect( selection.rangeCount ).to.equal( 1 );
  143. selection._setTo( [
  144. new Range( new Position( root, [ 2 ] ), new Position( root, [ 2 ] ) ),
  145. new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) )
  146. ] );
  147. expect( selection.rangeCount ).to.equal( 2 );
  148. } );
  149. } );
  150. describe( 'hasOwnRange', () => {
  151. it( 'should return true if selection has any ranges set', () => {
  152. selection._setTo( new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) );
  153. expect( selection.hasOwnRange ).to.be.true;
  154. } );
  155. it( 'should return false if selection has a default range', () => {
  156. expect( selection.hasOwnRange ).to.be.false;
  157. } );
  158. } );
  159. describe( 'addRange()', () => {
  160. it( 'should convert added Range to LiveRange', () => {
  161. selection._setTo( range );
  162. expect( selection._selection._ranges[ 0 ] ).to.be.instanceof( LiveRange );
  163. } );
  164. it( 'should throw an error when range is invalid', () => {
  165. expect( () => {
  166. selection._setTo( { invalid: 'range' } );
  167. } ).to.throw( CKEditorError, /model-selection-set-not-selectable/ );
  168. } );
  169. it( 'should not add a range that is in graveyard', () => {
  170. const spy = testUtils.sinon.stub( log, 'warn' );
  171. selection._setTo( Range.createIn( doc.graveyard ) );
  172. expect( selection._selection._ranges.length ).to.equal( 0 );
  173. expect( spy.calledOnce ).to.be.true;
  174. } );
  175. it( 'should refresh attributes', () => {
  176. const spy = testUtils.sinon.spy( selection._selection, '_updateAttributes' );
  177. selection._setTo( range );
  178. expect( spy.called ).to.be.true;
  179. } );
  180. } );
  181. describe( 'setCollapsedAt()', () => {
  182. it( 'detaches all existing ranges', () => {
  183. selection._setTo( [ range, liveRange ] );
  184. const spy = testUtils.sinon.spy( LiveRange.prototype, 'detach' );
  185. selection._setTo( root );
  186. expect( spy.calledTwice ).to.be.true;
  187. } );
  188. } );
  189. describe( 'destroy()', () => {
  190. it( 'should unbind all events', () => {
  191. selection._setTo( [ range, liveRange ] );
  192. const ranges = Array.from( selection._selection._ranges );
  193. sinon.spy( ranges[ 0 ], 'detach' );
  194. sinon.spy( ranges[ 1 ], 'detach' );
  195. selection.destroy();
  196. expect( ranges[ 0 ].detach.called ).to.be.true;
  197. expect( ranges[ 1 ].detach.called ).to.be.true;
  198. ranges[ 0 ].detach.restore();
  199. ranges[ 1 ].detach.restore();
  200. } );
  201. } );
  202. describe( 'moveFocusTo()', () => {
  203. it( 'modifies default range', () => {
  204. const startPos = selection.getFirstPosition();
  205. const endPos = Position.createAt( root, 'end' );
  206. selection._moveFocusTo( endPos );
  207. expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
  208. expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
  209. } );
  210. it( 'detaches the range it replaces', () => {
  211. const startPos = Position.createAt( root, 1 );
  212. const endPos = Position.createAt( root, 2 );
  213. const newEndPos = Position.createAt( root, 4 );
  214. const spy = testUtils.sinon.spy( LiveRange.prototype, 'detach' );
  215. selection._setTo( new Range( startPos, endPos ) );
  216. selection._moveFocusTo( newEndPos );
  217. expect( spy.calledOnce ).to.be.true;
  218. } );
  219. } );
  220. describe( 'setTo - removeAllRanges', () => {
  221. let spy, ranges;
  222. beforeEach( () => {
  223. selection._setTo( [ liveRange, range ] );
  224. spy = sinon.spy();
  225. selection.on( 'change:range', spy );
  226. ranges = Array.from( selection._selection._ranges );
  227. sinon.spy( ranges[ 0 ], 'detach' );
  228. sinon.spy( ranges[ 1 ], 'detach' );
  229. selection._setTo( null );
  230. } );
  231. afterEach( () => {
  232. ranges[ 0 ].detach.restore();
  233. ranges[ 1 ].detach.restore();
  234. } );
  235. it( 'should remove all stored ranges (and reset to default range)', () => {
  236. expect( Array.from( selection.getRanges() ).length ).to.equal( 1 );
  237. expect( selection.anchor.isEqual( new Position( root, [ 0, 0 ] ) ) ).to.be.true;
  238. expect( selection.focus.isEqual( new Position( root, [ 0, 0 ] ) ) ).to.be.true;
  239. } );
  240. it( 'should detach ranges', () => {
  241. expect( ranges[ 0 ].detach.called ).to.be.true;
  242. expect( ranges[ 1 ].detach.called ).to.be.true;
  243. } );
  244. it( 'should refresh attributes', () => {
  245. const spy = sinon.spy( selection._selection, '_updateAttributes' );
  246. selection._setTo( null );
  247. expect( spy.called ).to.be.true;
  248. } );
  249. } );
  250. describe( 'setRanges()', () => {
  251. it( 'should throw an error when range is invalid', () => {
  252. expect( () => {
  253. selection._setTo( [ { invalid: 'range' } ] );
  254. } ).to.throw( CKEditorError, /model-selection-added-not-range/ );
  255. } );
  256. it( 'should detach removed ranges', () => {
  257. selection._setTo( [ liveRange, range ] );
  258. const oldRanges = Array.from( selection._selection._ranges );
  259. sinon.spy( oldRanges[ 0 ], 'detach' );
  260. sinon.spy( oldRanges[ 1 ], 'detach' );
  261. selection._setTo( [] );
  262. expect( oldRanges[ 0 ].detach.called ).to.be.true;
  263. expect( oldRanges[ 1 ].detach.called ).to.be.true;
  264. } );
  265. it( 'should refresh attributes', () => {
  266. const spy = sinon.spy( selection._selection, '_updateAttributes' );
  267. selection._setTo( [ range ] );
  268. expect( spy.called ).to.be.true;
  269. } );
  270. // See #630.
  271. it( 'should refresh attributes – integration test for #630', () => {
  272. model.schema.extend( '$text', { allowIn: '$root' } );
  273. setData( model, 'f<$text italic="true">[o</$text><$text bold="true">ob]a</$text>r' );
  274. selection._setTo( [ Range.createFromPositionAndShift( selection.getLastRange().end, 0 ) ] );
  275. expect( selection.getAttribute( 'bold' ) ).to.equal( true );
  276. expect( selection.hasAttribute( 'italic' ) ).to.equal( false );
  277. expect( getData( model ) )
  278. .to.equal( 'f<$text italic="true">o</$text><$text bold="true">ob[]a</$text>r' );
  279. } );
  280. } );
  281. describe( 'getFirstRange()', () => {
  282. it( 'should return default range if no ranges were added', () => {
  283. const firstRange = selection.getFirstRange();
  284. expect( firstRange.start.isEqual( new Position( root, [ 0, 0 ] ) ) );
  285. expect( firstRange.end.isEqual( new Position( root, [ 0, 0 ] ) ) );
  286. } );
  287. } );
  288. describe( 'getLastRange()', () => {
  289. it( 'should return default range if no ranges were added', () => {
  290. const lastRange = selection.getLastRange();
  291. expect( lastRange.start.isEqual( new Position( root, [ 0, 0 ] ) ) );
  292. expect( lastRange.end.isEqual( new Position( root, [ 0, 0 ] ) ) );
  293. } );
  294. } );
  295. describe( '_isStoreAttributeKey', () => {
  296. it( 'should return true if given key is a key of an attribute stored in element by DocumentSelection', () => {
  297. expect( DocumentSelection._isStoreAttributeKey( fooStoreAttrKey ) ).to.be.true;
  298. } );
  299. it( 'should return false if given key is not a key of an attribute stored in element by DocumentSelection', () => {
  300. expect( DocumentSelection._isStoreAttributeKey( 'foo' ) ).to.be.false;
  301. } );
  302. } );
  303. // DocumentSelection uses LiveRanges so here are only simple test to see if integration is
  304. // working well, without getting into complicated corner cases.
  305. describe( 'after applying an operation should get updated and fire events', () => {
  306. let spyRange;
  307. beforeEach( () => {
  308. root.removeChildren( 0, root.childCount );
  309. root.insertChildren( 0, [
  310. new Element( 'p', [], new Text( 'abcdef' ) ),
  311. new Element( 'p', [], new Text( 'foobar' ) ),
  312. new Text( 'xyz' )
  313. ] );
  314. selection._setTo( new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 4 ] ) ) );
  315. spyRange = sinon.spy();
  316. selection.on( 'change:range', spyRange );
  317. } );
  318. describe( 'InsertOperation', () => {
  319. it( 'before selection', () => {
  320. selection.on( 'change:range', ( evt, data ) => {
  321. expect( data.directChange ).to.be.false;
  322. } );
  323. model.applyOperation( wrapInDelta(
  324. new InsertOperation(
  325. new Position( root, [ 0, 1 ] ),
  326. 'xyz',
  327. doc.version
  328. )
  329. ) );
  330. const range = selection.getFirstRange();
  331. expect( range.start.path ).to.deep.equal( [ 0, 5 ] );
  332. expect( range.end.path ).to.deep.equal( [ 1, 4 ] );
  333. expect( spyRange.calledOnce ).to.be.true;
  334. } );
  335. it( 'inside selection', () => {
  336. selection.on( 'change:range', ( evt, data ) => {
  337. expect( data.directChange ).to.be.false;
  338. } );
  339. model.applyOperation( wrapInDelta(
  340. new InsertOperation(
  341. new Position( root, [ 1, 0 ] ),
  342. 'xyz',
  343. doc.version
  344. )
  345. ) );
  346. const range = selection.getFirstRange();
  347. expect( range.start.path ).to.deep.equal( [ 0, 2 ] );
  348. expect( range.end.path ).to.deep.equal( [ 1, 7 ] );
  349. expect( spyRange.calledOnce ).to.be.true;
  350. } );
  351. } );
  352. describe( 'MoveOperation', () => {
  353. it( 'move range from before a selection', () => {
  354. selection.on( 'change:range', ( evt, data ) => {
  355. expect( data.directChange ).to.be.false;
  356. } );
  357. model.applyOperation( wrapInDelta(
  358. new MoveOperation(
  359. new Position( root, [ 0, 0 ] ),
  360. 2,
  361. new Position( root, [ 2 ] ),
  362. doc.version
  363. )
  364. ) );
  365. const range = selection.getFirstRange();
  366. expect( range.start.path ).to.deep.equal( [ 0, 0 ] );
  367. expect( range.end.path ).to.deep.equal( [ 1, 4 ] );
  368. expect( spyRange.calledOnce ).to.be.true;
  369. } );
  370. it( 'moved into before a selection', () => {
  371. selection.on( 'change:range', ( evt, data ) => {
  372. expect( data.directChange ).to.be.false;
  373. } );
  374. model.applyOperation( wrapInDelta(
  375. new MoveOperation(
  376. new Position( root, [ 2 ] ),
  377. 2,
  378. new Position( root, [ 0, 0 ] ),
  379. doc.version
  380. )
  381. ) );
  382. const range = selection.getFirstRange();
  383. expect( range.start.path ).to.deep.equal( [ 0, 4 ] );
  384. expect( range.end.path ).to.deep.equal( [ 1, 4 ] );
  385. expect( spyRange.calledOnce ).to.be.true;
  386. } );
  387. it( 'move range from inside of selection', () => {
  388. selection.on( 'change:range', ( evt, data ) => {
  389. expect( data.directChange ).to.be.false;
  390. } );
  391. model.applyOperation( wrapInDelta(
  392. new MoveOperation(
  393. new Position( root, [ 1, 0 ] ),
  394. 2,
  395. new Position( root, [ 2 ] ),
  396. doc.version
  397. )
  398. ) );
  399. const range = selection.getFirstRange();
  400. expect( range.start.path ).to.deep.equal( [ 0, 2 ] );
  401. expect( range.end.path ).to.deep.equal( [ 1, 2 ] );
  402. expect( spyRange.calledOnce ).to.be.true;
  403. } );
  404. it( 'moved range intersects with selection', () => {
  405. selection.on( 'change:range', ( evt, data ) => {
  406. expect( data.directChange ).to.be.false;
  407. } );
  408. model.applyOperation( wrapInDelta(
  409. new MoveOperation(
  410. new Position( root, [ 1, 3 ] ),
  411. 2,
  412. new Position( root, [ 4 ] ),
  413. doc.version
  414. )
  415. ) );
  416. const range = selection.getFirstRange();
  417. expect( range.start.path ).to.deep.equal( [ 0, 2 ] );
  418. expect( range.end.path ).to.deep.equal( [ 5 ] );
  419. expect( spyRange.calledOnce ).to.be.true;
  420. } );
  421. it( 'split inside selection (do not break selection)', () => {
  422. selection.on( 'change:range', ( evt, data ) => {
  423. expect( data.directChange ).to.be.false;
  424. } );
  425. const batch = new Batch();
  426. const splitDelta = new SplitDelta();
  427. const insertOperation = new InsertOperation(
  428. new Position( root, [ 2 ] ),
  429. new Element( 'p' ),
  430. 0
  431. );
  432. const moveOperation = new MoveOperation(
  433. new Position( root, [ 1, 2 ] ),
  434. 4,
  435. new Position( root, [ 2, 0 ] ),
  436. 1
  437. );
  438. batch.addDelta( splitDelta );
  439. splitDelta.addOperation( insertOperation );
  440. splitDelta.addOperation( moveOperation );
  441. model.applyOperation( insertOperation );
  442. model.applyOperation( moveOperation );
  443. const range = selection.getFirstRange();
  444. expect( range.start.path ).to.deep.equal( [ 0, 2 ] );
  445. expect( range.end.path ).to.deep.equal( [ 2, 2 ] );
  446. expect( spyRange.calledOnce ).to.be.true;
  447. } );
  448. } );
  449. describe( 'AttributeOperation', () => {
  450. it( 'changed range includes selection anchor', () => {
  451. const spyAttribute = sinon.spy();
  452. selection.on( 'change:attribute', spyAttribute );
  453. selection.on( 'change:attribute', ( evt, data ) => {
  454. expect( data.directChange ).to.be.false;
  455. expect( data.attributeKeys ).to.deep.equal( [ 'foo' ] );
  456. } );
  457. model.applyOperation( wrapInDelta(
  458. new AttributeOperation(
  459. new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
  460. 'foo',
  461. null,
  462. 'bar',
  463. doc.version
  464. )
  465. ) );
  466. expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  467. expect( spyAttribute.calledOnce ).to.be.true;
  468. } );
  469. it( 'should not overwrite previously set attributes', () => {
  470. selection._setAttribute( 'foo', 'xyz' );
  471. const spyAttribute = sinon.spy();
  472. selection.on( 'change:attribute', spyAttribute );
  473. model.applyOperation( wrapInDelta(
  474. new AttributeOperation(
  475. new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
  476. 'foo',
  477. null,
  478. 'bar',
  479. doc.version
  480. )
  481. ) );
  482. expect( selection.getAttribute( 'foo' ) ).to.equal( 'xyz' );
  483. expect( spyAttribute.called ).to.be.false;
  484. } );
  485. it( 'should not overwrite previously removed attributes', () => {
  486. selection._setAttribute( 'foo', 'xyz' );
  487. selection._removeAttribute( 'foo' );
  488. const spyAttribute = sinon.spy();
  489. selection.on( 'change:attribute', spyAttribute );
  490. model.applyOperation( wrapInDelta(
  491. new AttributeOperation(
  492. new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 5 ] ) ),
  493. 'foo',
  494. null,
  495. 'bar',
  496. doc.version
  497. )
  498. ) );
  499. expect( selection.hasAttribute( 'foo' ) ).to.be.false;
  500. expect( spyAttribute.called ).to.be.false;
  501. } );
  502. } );
  503. describe( 'RemoveOperation', () => {
  504. it( 'fix selection range if it ends up in graveyard #1', () => {
  505. selection._setTo( new Position( root, [ 1, 3 ] ) );
  506. model.applyOperation( wrapInDelta(
  507. new RemoveOperation(
  508. new Position( root, [ 1, 2 ] ),
  509. 2,
  510. new Position( doc.graveyard, [ 0 ] ),
  511. doc.version
  512. )
  513. ) );
  514. expect( selection.getFirstPosition().path ).to.deep.equal( [ 1, 2 ] );
  515. } );
  516. it( 'fix selection range if it ends up in graveyard #2', () => {
  517. selection._setTo( [ new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 1, 4 ] ) ) ] );
  518. model.applyOperation( wrapInDelta(
  519. new RemoveOperation(
  520. new Position( root, [ 1, 2 ] ),
  521. 2,
  522. new Position( doc.graveyard, [ 0 ] ),
  523. doc.version
  524. )
  525. ) );
  526. expect( selection.getFirstPosition().path ).to.deep.equal( [ 1, 2 ] );
  527. } );
  528. it( 'fix selection range if it ends up in graveyard #3', () => {
  529. selection._setTo( [ new Range( new Position( root, [ 1, 1 ] ), new Position( root, [ 1, 2 ] ) ) ] );
  530. model.applyOperation( wrapInDelta(
  531. new RemoveOperation(
  532. new Position( root, [ 1 ] ),
  533. 2,
  534. new Position( doc.graveyard, [ 0 ] ),
  535. doc.version
  536. )
  537. ) );
  538. expect( selection.getFirstPosition().path ).to.deep.equal( [ 0, 6 ] );
  539. } );
  540. it( 'fix selection range if it ends up in graveyard #4 - whole content removed', () => {
  541. model.applyOperation( wrapInDelta(
  542. new RemoveOperation(
  543. new Position( root, [ 0 ] ),
  544. 3,
  545. new Position( doc.graveyard, [ 0 ] ),
  546. doc.version
  547. )
  548. ) );
  549. expect( selection.getFirstPosition().path ).to.deep.equal( [ 0 ] );
  550. model.applyOperation( wrapInDelta(
  551. new InsertOperation(
  552. new Position( root, [ 0 ] ),
  553. new Element( 'p' ),
  554. doc.version
  555. )
  556. ) );
  557. // Now it's clear that it's the default range.
  558. expect( selection.getFirstPosition().path ).to.deep.equal( [ 0, 0 ] );
  559. } );
  560. } );
  561. } );
  562. describe( 'attributes', () => {
  563. let fullP, emptyP, rangeInFullP, rangeInEmptyP;
  564. beforeEach( () => {
  565. root.removeChildren( 0, root.childCount );
  566. root.appendChildren( [
  567. new Element( 'p', [], new Text( 'foobar' ) ),
  568. new Element( 'p', [], [] )
  569. ] );
  570. fullP = root.getChild( 0 );
  571. emptyP = root.getChild( 1 );
  572. rangeInFullP = new Range( new Position( root, [ 0, 4 ] ), new Position( root, [ 0, 4 ] ) );
  573. rangeInEmptyP = new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 1, 0 ] ) );
  574. // I've lost 30 mins debugging why my tests fail and that was due to the above code reusing
  575. // a root which wasn't empty (so the ranges didn't actualy make much sense).
  576. expect( root.childCount ).to.equal( 2 );
  577. } );
  578. describe( '_setAttribute()', () => {
  579. it( 'should store attribute if the selection is in empty node', () => {
  580. selection._setTo( [ rangeInEmptyP ] );
  581. selection._setAttribute( 'foo', 'bar' );
  582. expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  583. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  584. } );
  585. } );
  586. describe( '_setAttributesTo()', () => {
  587. it( 'should fire change:attribute event with correct parameters', done => {
  588. selection._setAttributesTo( { foo: 'bar', abc: 'def' } );
  589. selection.on( 'change:attribute', ( evt, data ) => {
  590. expect( data.directChange ).to.be.true;
  591. expect( data.attributeKeys ).to.deep.equal( [ 'abc', 'xxx' ] );
  592. done();
  593. } );
  594. selection._setAttributesTo( { foo: 'bar', xxx: 'yyy' } );
  595. } );
  596. it( 'should not fire change:attribute event if same attributes are set', () => {
  597. selection._setAttributesTo( { foo: 'bar', abc: 'def' } );
  598. const spy = sinon.spy();
  599. selection.on( 'change:attribute', spy );
  600. selection._setAttributesTo( { foo: 'bar', abc: 'def' } );
  601. expect( spy.called ).to.be.false;
  602. } );
  603. it( 'should remove all stored attributes and store the given ones if the selection is in empty node', () => {
  604. selection._setTo( [ rangeInEmptyP ] );
  605. selection._setAttribute( 'abc', 'xyz' );
  606. selection._setAttributesTo( { foo: 'bar' } );
  607. expect( selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
  608. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  609. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  610. expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
  611. } );
  612. } );
  613. describe( 'removeAttribute()', () => {
  614. it( 'should remove attribute set on the text fragment', () => {
  615. selection._setTo( [ rangeInFullP ] );
  616. selection._setAttribute( 'foo', 'bar' );
  617. selection._removeAttribute( 'foo' );
  618. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  619. expect( fullP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  620. } );
  621. it( 'should remove stored attribute if the selection is in empty node', () => {
  622. selection._setTo( [ rangeInEmptyP ] );
  623. selection._setAttribute( 'foo', 'bar' );
  624. selection._removeAttribute( 'foo' );
  625. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  626. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  627. } );
  628. } );
  629. describe( 'clearAttributes()', () => {
  630. it( 'should remove all stored attributes if the selection is in empty node', () => {
  631. selection._setTo( [ rangeInEmptyP ] );
  632. selection._setAttribute( 'foo', 'bar' );
  633. selection._setAttribute( 'abc', 'xyz' );
  634. selection._clearAttributes();
  635. expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
  636. expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
  637. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  638. expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
  639. } );
  640. } );
  641. describe( '_getStoredAttributes()', () => {
  642. it( 'should return no values if there are no ranges in selection', () => {
  643. const values = Array.from( selection._getStoredAttributes() );
  644. expect( values ).to.deep.equal( [] );
  645. } );
  646. } );
  647. describe( 'are updated on a direct range change', () => {
  648. beforeEach( () => {
  649. root.insertChildren( 0, [
  650. new Element( 'p', { p: true } ),
  651. new Text( 'a', { a: true } ),
  652. new Element( 'p', { p: true } ),
  653. new Text( 'b', { b: true } ),
  654. new Text( 'c', { c: true } ),
  655. new Element( 'p', [], [
  656. new Text( 'd', { d: true } )
  657. ] ),
  658. new Element( 'p', { p: true } ),
  659. new Text( 'e', { e: true } )
  660. ] );
  661. } );
  662. it( 'if selection is a range, should find first character in it and copy it\'s attributes', () => {
  663. selection._setTo( [ new Range( new Position( root, [ 2 ] ), new Position( root, [ 5 ] ) ) ] );
  664. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'b', true ] ] );
  665. // Step into elements when looking for first character:
  666. selection._setTo( [ new Range( new Position( root, [ 5 ] ), new Position( root, [ 7 ] ) ) ] );
  667. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'd', true ] ] );
  668. } );
  669. it( 'if selection is collapsed it should seek a character to copy that character\'s attributes', () => {
  670. // Take styles from character before selection.
  671. selection._setTo( [ new Range( new Position( root, [ 2 ] ), new Position( root, [ 2 ] ) ) ] );
  672. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'a', true ] ] );
  673. // If there are none,
  674. // Take styles from character after selection.
  675. selection._setTo( [ new Range( new Position( root, [ 3 ] ), new Position( root, [ 3 ] ) ) ] );
  676. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'b', true ] ] );
  677. // If there are none,
  678. // Look from the selection position to the beginning of node looking for character to take attributes from.
  679. selection._setTo( [ new Range( new Position( root, [ 6 ] ), new Position( root, [ 6 ] ) ) ] );
  680. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'c', true ] ] );
  681. // If there are none,
  682. // Look from the selection position to the end of node looking for character to take attributes from.
  683. selection._setTo( [ new Range( new Position( root, [ 0 ] ), new Position( root, [ 0 ] ) ) ] );
  684. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'a', true ] ] );
  685. // If there are no characters to copy attributes from, use stored attributes.
  686. selection._setTo( [ new Range( new Position( root, [ 0, 0 ] ), new Position( root, [ 0, 0 ] ) ) ] );
  687. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [] );
  688. } );
  689. it( 'should overwrite any previously set attributes', () => {
  690. selection._setTo( new Position( root, [ 5, 0 ] ) );
  691. selection._setAttribute( 'x', true );
  692. selection._setAttribute( 'y', true );
  693. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'd', true ], [ 'x', true ], [ 'y', true ] ] );
  694. selection._setTo( new Position( root, [ 1 ] ) );
  695. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'a', true ] ] );
  696. } );
  697. it( 'should fire change:attribute event', () => {
  698. const spy = sinon.spy();
  699. selection.on( 'change:attribute', spy );
  700. selection._setTo( [ new Range( new Position( root, [ 2 ] ), new Position( root, [ 5 ] ) ) ] );
  701. expect( spy.calledOnce ).to.be.true;
  702. } );
  703. it( 'should not fire change:attribute event if attributes did not change', () => {
  704. selection._setTo( new Position( root, [ 5, 0 ] ) );
  705. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'd', true ] ] );
  706. const spy = sinon.spy();
  707. selection.on( 'change:attribute', spy );
  708. selection._setTo( new Position( root, [ 5, 1 ] ) );
  709. expect( Array.from( selection.getAttributes() ) ).to.deep.equal( [ [ 'd', true ] ] );
  710. expect( spy.called ).to.be.false;
  711. } );
  712. } );
  713. // #986
  714. describe( 'are not inherited from the inside of object elements', () => {
  715. beforeEach( () => {
  716. model.schema.register( 'image', {
  717. isObject: true
  718. } );
  719. model.schema.extend( 'image', { allowIn: '$root' } );
  720. model.schema.extend( 'image', { allowIn: '$block' } );
  721. model.schema.register( 'caption' );
  722. model.schema.extend( 'caption', { allowIn: 'image' } );
  723. model.schema.extend( '$text', {
  724. allowIn: [ 'image', 'caption' ],
  725. allowAttributes: 'bold'
  726. } );
  727. } );
  728. it( 'ignores attributes inside an object if selection contains that object', () => {
  729. setData( model, '<p>[<image><$text bold="true">Caption for the image.</$text></image>]</p>' );
  730. expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
  731. } );
  732. it( 'ignores attributes inside an object if selection contains that object (deeper structure)', () => {
  733. setData( model, '<p>[<image><caption><$text bold="true">Caption for the image.</$text></caption></image>]</p>' );
  734. expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
  735. } );
  736. it( 'ignores attributes inside an object if selection contains that object (block level)', () => {
  737. setData( model, '<p>foo</p>[<image><$text bold="true">Caption for the image.</$text></image>]<p>foo</p>' );
  738. expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
  739. } );
  740. it( 'reads attributes from text even if the selection contains an object', () => {
  741. setData( model, '<p>x<$text bold="true">[bar</$text><image></image>foo]</p>' );
  742. expect( selection.getAttribute( 'bold' ) ).to.equal( true );
  743. } );
  744. it( 'reads attributes when the entire selection inside an object', () => {
  745. setData( model, '<p><image><caption><$text bold="true">[bar]</$text></caption></image></p>' );
  746. expect( selection.getAttribute( 'bold' ) ).to.equal( true );
  747. } );
  748. it( 'stops reading attributes if selection starts with an object', () => {
  749. setData( model, '<p>[<image></image><$text bold="true">bar]</$text></p>' );
  750. expect( selection.hasAttribute( 'bold' ) ).to.equal( false );
  751. } );
  752. } );
  753. describe( 'parent element\'s attributes', () => {
  754. it( 'are set using a normal batch', () => {
  755. const batchTypes = [];
  756. model.on( 'applyOperation', ( event, args ) => {
  757. const operation = args[ 0 ];
  758. const batch = operation.delta.batch;
  759. batchTypes.push( batch.type );
  760. } );
  761. selection._setTo( [ rangeInEmptyP ] );
  762. selection._setAttribute( 'foo', 'bar' );
  763. expect( batchTypes ).to.deep.equal( [ 'default' ] );
  764. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  765. } );
  766. it( 'are removed when any content is inserted (reuses the same batch)', () => {
  767. // Dedupe batches by using a map (multiple change events will be fired).
  768. const batchTypes = new Map();
  769. selection._setTo( [ rangeInEmptyP ] );
  770. selection._setAttribute( 'foo', 'bar' );
  771. selection._setAttribute( 'abc', 'bar' );
  772. model.on( 'applyOperation', ( event, args ) => {
  773. const operation = args[ 0 ];
  774. const batch = operation.delta.batch;
  775. batchTypes.set( batch, batch.type );
  776. } );
  777. model.change( writer => {
  778. writer.insertText( 'x', rangeInEmptyP.start );
  779. } );
  780. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  781. expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
  782. expect( Array.from( batchTypes.values() ) ).to.deep.equal( [ 'default' ] );
  783. } );
  784. it( 'are removed when any content is moved into', () => {
  785. selection._setTo( [ rangeInEmptyP ] );
  786. selection._setAttribute( 'foo', 'bar' );
  787. model.change( writer => {
  788. writer.move( Range.createOn( fullP.getChild( 0 ) ), rangeInEmptyP.start );
  789. } );
  790. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  791. } );
  792. it( 'are removed when containing element is merged with a non-empty element', () => {
  793. const emptyP2 = new Element( 'p', null, 'x' );
  794. root.appendChildren( emptyP2 );
  795. emptyP.setAttribute( fooStoreAttrKey, 'bar' );
  796. emptyP2.setAttribute( fooStoreAttrKey, 'bar' );
  797. model.change( writer => {
  798. // <emptyP>{}<emptyP2>
  799. writer.merge( Position.createAfter( emptyP ) );
  800. } );
  801. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  802. expect( emptyP.parent ).to.equal( root ); // Just to be sure we're checking the right element.
  803. } );
  804. it( 'are removed even when there is no selection in it', () => {
  805. emptyP.setAttribute( fooStoreAttrKey, 'bar' );
  806. selection._setTo( [ rangeInFullP ] );
  807. model.change( writer => {
  808. writer.insertText( 'x', rangeInEmptyP.start );
  809. } );
  810. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  811. } );
  812. it( 'are removed only once in case of multi-op deltas', () => {
  813. let batch;
  814. const emptyP2 = new Element( 'p', null, 'x' );
  815. root.appendChildren( emptyP2 );
  816. emptyP.setAttribute( fooStoreAttrKey, 'bar' );
  817. emptyP2.setAttribute( fooStoreAttrKey, 'bar' );
  818. model.change( writer => {
  819. batch = writer.batch;
  820. // <emptyP>{}<emptyP2>
  821. writer.merge( Position.createAfter( emptyP ) );
  822. } );
  823. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  824. // Attribute delta is only one.
  825. expect( Array.from( batch.deltas, delta => delta.type ) ).to.deep.equal( [ 'merge', 'attribute' ] );
  826. } );
  827. it( 'uses model change to clear attributes', () => {
  828. selection._setTo( [ rangeInEmptyP ] );
  829. selection._setAttribute( 'foo', 'bar' );
  830. model.change( writer => {
  831. writer.insertText( 'x', rangeInEmptyP.start );
  832. // `emptyP` still has the attribute, because attribute clearing is in enqueued block.
  833. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.true;
  834. } );
  835. // When the dust settles, `emptyP` should not have the attribute.
  836. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
  837. } );
  838. it( 'are not removed or merged when containing element is merged with another empty element', () => {
  839. const emptyP2 = new Element( 'p', null );
  840. root.appendChildren( emptyP2 );
  841. emptyP.setAttribute( fooStoreAttrKey, 'bar' );
  842. emptyP2.setAttribute( abcStoreAttrKey, 'bar' );
  843. expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.true;
  844. expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
  845. model.change( writer => {
  846. // <emptyP>{}<emptyP2>
  847. writer.merge( Position.createAfter( emptyP ) );
  848. } );
  849. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  850. expect( emptyP.parent ).to.equal( root ); // Just to be sure we're checking the right element.
  851. } );
  852. <<<<<<< HEAD
  853. =======
  854. it( 'are not removed on transparent batches', () => {
  855. selection._setTo( [ rangeInEmptyP ] );
  856. selection._setAttribute( 'foo', 'bar' );
  857. model.enqueueChange( 'transparent', writer => {
  858. sinon.spy( model, 'enqueueChange' );
  859. writer.insertText( 'x', rangeInEmptyP.start );
  860. expect( model.enqueueChange.called ).to.be.false;
  861. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  862. } );
  863. } );
  864. >>>>>>> WIP - DocumentSelection. part 2.
  865. // Rename and some other deltas don't specify range in doc#change event.
  866. // So let's see if there's no crash or something.
  867. it( 'are not removed on rename', () => {
  868. selection._setTo( [ rangeInEmptyP ] );
  869. selection._setAttribute( 'foo', 'bar' );
  870. sinon.spy( model, 'enqueueChange' );
  871. model.change( writer => {
  872. writer.rename( emptyP, 'pnew' );
  873. } );
  874. expect( model.enqueueChange.called ).to.be.false;
  875. expect( emptyP.getAttribute( fooStoreAttrKey ) ).to.equal( 'bar' );
  876. } );
  877. } );
  878. } );
  879. it( 'should throw if one of ranges starts or ends inside surrogate pair', () => {
  880. root.removeChildren( 0, root.childCount );
  881. root.appendChildren( '\uD83D\uDCA9' );
  882. expect( () => {
  883. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 0, root, 1 ) ] );
  884. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  885. expect( () => {
  886. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 1, root, 2 ) ] );
  887. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  888. } );
  889. it( 'should throw if one of ranges starts or ends between base character and combining mark', () => {
  890. root.removeChildren( 0, root.childCount );
  891. root.appendChildren( 'foo̻̐ͩbar' );
  892. expect( () => {
  893. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 3, root, 9 ) ] );
  894. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  895. expect( () => {
  896. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 4, root, 9 ) ] );
  897. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  898. expect( () => {
  899. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 5, root, 9 ) ] );
  900. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  901. expect( () => {
  902. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 1, root, 3 ) ] );
  903. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  904. expect( () => {
  905. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 1, root, 4 ) ] );
  906. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  907. expect( () => {
  908. doc.selection.setRanges( [ Range.createFromParentsAndOffsets( root, 1, root, 5 ) ] );
  909. } ).to.throw( CKEditorError, /document-selection-wrong-position/ );
  910. } );
  911. } );