8
0

enableenginedebug.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import { default as enableEngineDebug, disableEngineDebug } from '../../src/dev-utils/enableenginedebug';
  6. import StandardEditor from '@ckeditor/ckeditor5-core/src/editor/standardeditor';
  7. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  8. import ModelPosition from '../../src/model/position';
  9. import ModelRange from '../../src/model/range';
  10. import ModelText from '../../src/model/text';
  11. import ModelTextProxy from '../../src/model/textproxy';
  12. import ModelElement from '../../src/model/element';
  13. import AttributeOperation from '../../src/model/operation/attributeoperation';
  14. import InsertOperation from '../../src/model/operation/insertoperation';
  15. import MarkerOperation from '../../src/model/operation/markeroperation';
  16. import MoveOperation from '../../src/model/operation/moveoperation';
  17. import NoOperation from '../../src/model/operation/nooperation';
  18. import RenameOperation from '../../src/model/operation/renameoperation';
  19. import RootAttributeOperation from '../../src/model/operation/rootattributeoperation';
  20. import RemoveOperation from '../../src/model/operation/removeoperation';
  21. import DeltaFactory from '../../src/model/delta/deltafactory';
  22. import Delta from '../../src/model/delta/delta';
  23. import { default as AttributeDelta, RootAttributeDelta } from '../../src/model/delta/attributedelta';
  24. import InsertDelta from '../../src/model/delta/insertdelta';
  25. import MarkerDelta from '../../src/model/delta/markerdelta';
  26. import MergeDelta from '../../src/model/delta/mergedelta';
  27. import MoveDelta from '../../src/model/delta/movedelta';
  28. import RenameDelta from '../../src/model/delta/renamedelta';
  29. import SplitDelta from '../../src/model/delta/splitdelta';
  30. import UnwrapDelta from '../../src/model/delta/unwrapdelta';
  31. import WrapDelta from '../../src/model/delta/wrapdelta';
  32. import deltaTransform from '../../src/model/delta/transform';
  33. import ModelDocument from '../../src/model/document';
  34. import ModelDocumentFragment from '../../src/model/documentfragment';
  35. import ViewDocument from '../../src/view/document';
  36. import ViewAttributeElement from '../../src/view/attributeelement';
  37. import ViewContainerElement from '../../src/view/containerelement';
  38. import ViewText from '../../src/view/text';
  39. import ViewTextProxy from '../../src/view/textproxy';
  40. import ViewDocumentFragment from '../../src/view/documentfragment';
  41. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  42. testUtils.createSinonSandbox();
  43. /* global document */
  44. after( () => {
  45. disableEngineDebug();
  46. } );
  47. describe( 'enableEngineDebug', () => {
  48. it( 'should return plugin class', () => {
  49. const result = enableEngineDebug();
  50. expect( result.prototype ).to.be.instanceof( Plugin );
  51. } );
  52. it( 'should not throw when called multiple times', () => {
  53. enableEngineDebug();
  54. enableEngineDebug();
  55. const result = enableEngineDebug();
  56. expect( result.prototype ).to.be.instanceof( Plugin );
  57. } );
  58. } );
  59. describe( 'debug tools', () => {
  60. let DebugPlugin, log, error;
  61. class TestEditor extends StandardEditor {
  62. constructor( ...args ) {
  63. super( ...args );
  64. this.document.createRoot( 'main' );
  65. this.editing.createRoot( this.element, 'main' );
  66. }
  67. }
  68. before( () => {
  69. log = sinon.spy();
  70. error = sinon.spy();
  71. DebugPlugin = enableEngineDebug( { log, error } );
  72. } );
  73. afterEach( () => {
  74. log.reset();
  75. } );
  76. describe( 'should provide logging tools', () => {
  77. let modelDoc, modelRoot, modelElement, modelDocFrag;
  78. beforeEach( () => {
  79. modelDoc = new ModelDocument();
  80. modelRoot = modelDoc.createRoot();
  81. modelElement = new ModelElement( 'paragraph', null, new ModelText( 'foo' ) );
  82. modelDocFrag = new ModelDocumentFragment( [ new ModelText( 'bar' ) ] );
  83. } );
  84. it( 'for ModelText', () => {
  85. const foo = new ModelText( 'foo', { foo: 'bar' } );
  86. expect( foo.toString() ).to.equal( '#foo' );
  87. foo.log();
  88. expect( log.calledWithExactly( 'ModelText: #foo' ) ).to.be.true;
  89. foo.logExtended();
  90. expect( log.calledWithExactly( 'ModelText: #foo, attrs: {"foo":"bar"}' ) ).to.be.true;
  91. } );
  92. it( 'for ModelTextProxy', () => {
  93. const foo = new ModelText( 'foo', { foo: 'bar' } );
  94. const proxy = new ModelTextProxy( foo, 1, 1 );
  95. expect( proxy.toString() ).to.equal( '#o' );
  96. proxy.log();
  97. expect( log.calledWithExactly( 'ModelTextProxy: #o' ) ).to.be.true;
  98. proxy.logExtended();
  99. expect( log.calledWithExactly( 'ModelTextProxy: #o, attrs: {"foo":"bar"}' ) ).to.be.true;
  100. } );
  101. it( 'for ModelElement', () => {
  102. const paragraph = new ModelElement( 'paragraph', { foo: 'bar' }, new ModelText( 'foo' ) );
  103. expect( paragraph.toString() ).to.equal( '<paragraph>' );
  104. paragraph.log();
  105. expectLog( 'ModelElement: <paragraph>' );
  106. paragraph.logExtended();
  107. expectLog( 'ModelElement: <paragraph>, 1 children, attrs: {"foo":"bar"}' );
  108. sinon.spy( paragraph, 'logExtended' );
  109. paragraph.logAll();
  110. expect( paragraph.logExtended.called ).to.be.true;
  111. expectLog( 'ModelText: #foo' );
  112. } );
  113. it( 'for ModelRootElement', () => {
  114. modelRoot.log();
  115. expectLog( 'ModelRootElement: main' );
  116. } );
  117. it( 'for ModelDocumentFragment', () => {
  118. modelDocFrag.log();
  119. expectLog( 'ModelDocumentFragment: documentFragment' );
  120. } );
  121. it( 'for ModelPosition', () => {
  122. const posInRoot = new ModelPosition( modelRoot, [ 0, 1, 0 ] );
  123. const posInElement = new ModelPosition( modelElement, [ 0 ] );
  124. const posInDocFrag = new ModelPosition( modelDocFrag, [ 2, 3 ] );
  125. expect( posInRoot.toString() ).to.equal( 'main [ 0, 1, 0 ]' );
  126. expect( posInElement.toString() ).to.equal( '<paragraph> [ 0 ]' );
  127. expect( posInDocFrag.toString() ).to.equal( 'documentFragment [ 2, 3 ]' );
  128. posInRoot.log();
  129. expectLog( 'ModelPosition: main [ 0, 1, 0 ]' );
  130. } );
  131. it( 'for ModelRange', () => {
  132. const rangeInRoot = ModelRange.createIn( modelRoot );
  133. const rangeInElement = ModelRange.createIn( modelElement );
  134. const rangeInDocFrag = ModelRange.createIn( modelDocFrag );
  135. expect( rangeInRoot.toString() ).to.equal( 'main [ 0 ] - [ 0 ]' );
  136. expect( rangeInElement.toString() ).to.equal( '<paragraph> [ 0 ] - [ 3 ]' );
  137. expect( rangeInDocFrag.toString() ).to.equal( 'documentFragment [ 0 ] - [ 3 ]' );
  138. rangeInRoot.log();
  139. expectLog( 'ModelRange: main [ 0 ] - [ 0 ]' );
  140. } );
  141. it( 'for ViewText', () => {
  142. const foo = new ViewText( 'foo' );
  143. expect( foo.toString() ).to.equal( '#foo' );
  144. foo.log();
  145. expect( log.calledWithExactly( 'ViewText: #foo' ) ).to.be.true;
  146. foo.logExtended();
  147. expect( log.calledWithExactly( 'ViewText: #foo' ) ).to.be.true;
  148. } );
  149. it( 'for ViewTextProxy', () => {
  150. const foo = new ViewText( 'foo', { foo: 'bar' } );
  151. const proxy = new ViewTextProxy( foo, 1, 1 );
  152. expect( proxy.toString() ).to.equal( '#o' );
  153. proxy.log();
  154. expect( log.calledWithExactly( 'ViewTextProxy: #o' ) ).to.be.true;
  155. proxy.logExtended();
  156. expect( log.calledWithExactly( 'ViewTextProxy: #o' ) ).to.be.true;
  157. } );
  158. describe( 'for operations', () => {
  159. beforeEach( () => {
  160. modelRoot.appendChildren( [ new ModelText( 'foobar' ) ] );
  161. } );
  162. it( 'AttributeOperation', () => {
  163. const op = new AttributeOperation( ModelRange.createIn( modelRoot ), 'key', null, { foo: 'bar' }, 0 );
  164. expect( op.toString() ).to.equal( 'AttributeOperation( 0 ): "key": null -> {"foo":"bar"}, main [ 0 ] - [ 6 ]' );
  165. op.log();
  166. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  167. } );
  168. it( 'InsertOperation (text node)', () => {
  169. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), [ new ModelText( 'abc' ) ], 0 );
  170. expect( op.toString() ).to.equal( 'InsertOperation( 0 ): #abc -> main [ 3 ]' );
  171. op.log();
  172. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  173. } );
  174. it( 'InsertOperation (element)', () => {
  175. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), [ new ModelElement( 'paragraph' ) ], 0 );
  176. expect( op.toString() ).to.equal( 'InsertOperation( 0 ): <paragraph> -> main [ 3 ]' );
  177. op.log();
  178. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  179. } );
  180. it( 'InsertOperation (multiple nodes)', () => {
  181. const nodes = [ new ModelText( 'x' ), new ModelElement( 'y' ), new ModelText( 'z' ) ];
  182. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), nodes, 0 );
  183. expect( op.toString() ).to.equal( 'InsertOperation( 0 ): [ 3 ] -> main [ 3 ]' );
  184. op.log();
  185. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  186. } );
  187. it( 'MarkerOperation', () => {
  188. const op = new MarkerOperation( 'marker', null, ModelRange.createIn( modelRoot ), modelDoc.markers, 0 );
  189. expect( op.toString() ).to.equal( 'MarkerOperation( 0 ): "marker": null -> main [ 0 ] - [ 6 ]' );
  190. op.log();
  191. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  192. } );
  193. it( 'MoveOperation', () => {
  194. const op = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( modelRoot, 6 ), 0 );
  195. expect( op.toString() ).to.equal( 'MoveOperation( 0 ): main [ 1 ] - [ 3 ] -> main [ 6 ]' );
  196. op.log();
  197. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  198. } );
  199. it( 'MoveOperation sticky', () => {
  200. const op = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( modelRoot, 6 ), 0 );
  201. op.isSticky = true;
  202. expect( op.toString() ).to.equal( 'MoveOperation( 0 ): main [ 1 ] - [ 3 ] -> main [ 6 ] (sticky)' );
  203. op.log();
  204. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  205. } );
  206. it( 'NoOperation', () => {
  207. const op = new NoOperation( 0 );
  208. expect( op.toString() ).to.equal( 'NoOperation( 0 )' );
  209. op.log();
  210. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  211. } );
  212. it( 'RenameOperation', () => {
  213. const op = new RenameOperation( ModelPosition.createAt( modelRoot, 1 ), 'old', 'new', 0 );
  214. expect( op.toString() ).to.equal( 'RenameOperation( 0 ): main [ 1 ]: "old" -> "new"' );
  215. op.log();
  216. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  217. } );
  218. it( 'RootAttributeOperation', () => {
  219. const op = new RootAttributeOperation( modelRoot, 'key', 'old', null, 0 );
  220. expect( op.toString() ).to.equal( 'RootAttributeOperation( 0 ): "key": "old" -> null, main' );
  221. op.log();
  222. expect( log.calledWithExactly( op.toString() ) ).to.be.true;
  223. } );
  224. } );
  225. describe( 'for deltas', () => {
  226. it( 'Delta', () => {
  227. const delta = new Delta();
  228. const op = { log: sinon.spy() };
  229. delta.addOperation( op );
  230. sinon.spy( delta, 'log' );
  231. delta.logAll();
  232. expect( op.log.called ).to.be.true;
  233. expect( delta.log.called ).to.be.true;
  234. } );
  235. it( 'AttributeDelta', () => {
  236. modelRoot.appendChildren( new ModelText( 'foobar' ) );
  237. const delta = new AttributeDelta();
  238. const op = new AttributeOperation( ModelRange.createIn( modelRoot ), 'key', null, { foo: 'bar' }, 0 );
  239. delta.addOperation( op );
  240. expect( delta.toString() ).to.equal( 'AttributeDelta( 0 ): "key": -> {"foo":"bar"}, main [ 0 ] - [ 6 ], 1 ops' );
  241. delta.log();
  242. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  243. } );
  244. it( 'InsertDelta (text node)', () => {
  245. const delta = new InsertDelta();
  246. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), [ new ModelText( 'abc' ) ], 0 );
  247. delta.addOperation( op );
  248. expect( delta.toString() ).to.equal( 'InsertDelta( 0 ): #abc -> main [ 3 ]' );
  249. delta.log();
  250. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  251. } );
  252. it( 'InsertDelta (element)', () => {
  253. const delta = new InsertDelta();
  254. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), [ new ModelElement( 'paragraph' ) ], 0 );
  255. delta.addOperation( op );
  256. expect( delta.toString() ).to.equal( 'InsertDelta( 0 ): <paragraph> -> main [ 3 ]' );
  257. delta.log();
  258. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  259. } );
  260. it( 'InsertDelta (multiple nodes)', () => {
  261. const delta = new InsertDelta();
  262. const nodes = [ new ModelText( 'x' ), new ModelElement( 'y' ), new ModelText( 'z' ) ];
  263. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 3 ), nodes, 0 );
  264. delta.addOperation( op );
  265. expect( delta.toString() ).to.equal( 'InsertDelta( 0 ): [ 3 ] -> main [ 3 ]' );
  266. delta.log();
  267. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  268. } );
  269. it( 'MarkerDelta', () => {
  270. modelRoot.appendChildren( new ModelText( 'foobar' ) );
  271. const delta = new MarkerDelta();
  272. const op = new MarkerOperation( 'marker', null, ModelRange.createIn( modelRoot ), modelDoc.markers, 0 );
  273. delta.addOperation( op );
  274. expect( delta.toString() ).to.equal( 'MarkerDelta( 0 ): "marker": null -> main [ 0 ] - [ 6 ]' );
  275. delta.log();
  276. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  277. } );
  278. it( 'MergeDelta', () => {
  279. const otherRoot = modelDoc.createRoot( '$root', 'otherRoot' );
  280. const firstEle = new ModelElement( 'paragraph' );
  281. const removedEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  282. otherRoot.appendChildren( [ firstEle, removedEle ] );
  283. const graveyard = modelDoc.graveyard;
  284. const delta = new MergeDelta();
  285. const move = new MoveOperation( ModelPosition.createAt( removedEle, 0 ), 3, ModelPosition.createAt( firstEle, 0 ), 0 );
  286. const remove = new RemoveOperation(
  287. ModelPosition.createBefore( removedEle ),
  288. 1,
  289. ModelPosition.createAt( graveyard, 0 ),
  290. 1
  291. );
  292. delta.addOperation( move );
  293. delta.addOperation( remove );
  294. expect( delta.toString() ).to.equal( 'MergeDelta( 0 ): otherRoot [ 1 ]' );
  295. delta.log();
  296. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  297. } );
  298. it( 'MergeDelta - NoOperation as second operation', () => {
  299. const otherRoot = modelDoc.createRoot( '$root', 'otherRoot' );
  300. const firstEle = new ModelElement( 'paragraph' );
  301. const removedEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  302. otherRoot.appendChildren( [ firstEle, removedEle ] );
  303. const delta = new MergeDelta();
  304. const move = new MoveOperation( ModelPosition.createAt( removedEle, 0 ), 3, ModelPosition.createAt( firstEle, 0 ), 0 );
  305. delta.addOperation( move );
  306. delta.addOperation( new NoOperation( 1 ) );
  307. expect( delta.toString() ).to.equal( 'MergeDelta( 0 ): (move from otherRoot [ 1, 0 ])' );
  308. delta.log();
  309. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  310. } );
  311. it( 'MoveDelta', () => {
  312. const delta = new MoveDelta();
  313. const move1 = new MoveOperation( ModelPosition.createAt( modelRoot, 0 ), 1, ModelPosition.createAt( modelRoot, 3 ), 0 );
  314. const move2 = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 1, ModelPosition.createAt( modelRoot, 6 ), 0 );
  315. delta.addOperation( move1 );
  316. delta.addOperation( move2 );
  317. expect( delta.toString() ).to.equal( 'MoveDelta( 0 ): main [ 0 ] - [ 1 ] -> main [ 3 ]; main [ 1 ] - [ 2 ] -> main [ 6 ]' );
  318. delta.log();
  319. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  320. } );
  321. it( 'RenameDelta', () => {
  322. const delta = new RenameDelta();
  323. const op = new RenameOperation( ModelPosition.createAt( modelRoot, 1 ), 'old', 'new', 0 );
  324. delta.addOperation( op );
  325. expect( delta.toString() ).to.equal( 'RenameDelta( 0 ): main [ 1 ]: "old" -> "new"' );
  326. delta.log();
  327. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  328. } );
  329. it( 'RootAttributeDelta', () => {
  330. const delta = new RootAttributeDelta();
  331. const op = new RootAttributeOperation( modelRoot, 'key', 'old', null, 0 );
  332. delta.addOperation( op );
  333. expect( delta.toString() ).to.equal( 'RootAttributeDelta( 0 ): "key": "old" -> null, main' );
  334. delta.log();
  335. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  336. } );
  337. it( 'SplitDelta', () => {
  338. const otherRoot = modelDoc.createRoot( 'main', 'otherRoot' );
  339. const splitEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  340. otherRoot.appendChildren( [ splitEle ] );
  341. const delta = new SplitDelta();
  342. const insert = new InsertOperation( ModelPosition.createAt( otherRoot, 1 ), [ new ModelElement( 'paragraph' ) ], 0 );
  343. const move = new MoveOperation( ModelPosition.createAt( splitEle, 1 ), 2, new ModelPosition( otherRoot, [ 1, 0 ] ), 1 );
  344. delta.addOperation( insert );
  345. delta.addOperation( move );
  346. expect( delta.toString() ).to.equal( 'SplitDelta( 0 ): otherRoot [ 0, 1 ]' );
  347. delta.log();
  348. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  349. } );
  350. it( 'SplitDelta - NoOperation as second operation', () => {
  351. const otherRoot = modelDoc.createRoot( 'main', 'otherRoot' );
  352. const splitEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  353. otherRoot.appendChildren( [ splitEle ] );
  354. const delta = new SplitDelta();
  355. const insert = new InsertOperation( ModelPosition.createAt( otherRoot, 1 ), [ new ModelElement( 'paragraph' ) ], 0 );
  356. const move = new NoOperation( 1 );
  357. delta.addOperation( insert );
  358. delta.addOperation( move );
  359. expect( delta.toString() ).to.equal( 'SplitDelta( 0 ): (clone to otherRoot [ 1 ])' );
  360. delta.log();
  361. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  362. } );
  363. it( 'SplitDelta - NoOperation as second operation, MoveOperation as first operation', () => {
  364. const otherRoot = modelDoc.createRoot( 'main', 'otherRoot' );
  365. const delta = new SplitDelta();
  366. const insert = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 1, ModelPosition.createAt( otherRoot, 1 ), 0 );
  367. const move = new NoOperation( 1 );
  368. delta.addOperation( insert );
  369. delta.addOperation( move );
  370. expect( delta.toString() ).to.equal( 'SplitDelta( 0 ): (clone to otherRoot [ 1 ])' );
  371. delta.log();
  372. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  373. } );
  374. it( 'UnwrapDelta', () => {
  375. const otherRoot = modelDoc.createRoot( 'main', 'otherRoot' );
  376. const unwrapEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  377. otherRoot.appendChildren( [ unwrapEle ] );
  378. const graveyard = modelDoc.graveyard;
  379. const delta = new UnwrapDelta();
  380. const move = new MoveOperation( ModelPosition.createAt( unwrapEle, 0 ), 3, ModelPosition.createAt( otherRoot, 0 ), 0 );
  381. const remove = new RemoveOperation( ModelPosition.createAt( otherRoot, 3 ), 1, ModelPosition.createAt( graveyard, 0 ), 1 );
  382. delta.addOperation( move );
  383. delta.addOperation( remove );
  384. expect( delta.toString() ).to.equal( 'UnwrapDelta( 0 ): otherRoot [ 0 ]' );
  385. delta.log();
  386. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  387. } );
  388. it( 'WrapDelta', () => {
  389. const delta = new WrapDelta();
  390. const insert = new InsertOperation( ModelPosition.createAt( modelRoot, 6 ), new ModelElement( 'paragraph' ), 0 );
  391. const move = new MoveOperation( ModelPosition.createAt( modelRoot, 0 ), 6, new ModelPosition( modelRoot, [ 1, 0 ] ), 1 );
  392. delta.addOperation( insert );
  393. delta.addOperation( move );
  394. expect( delta.toString() ).to.equal( 'WrapDelta( 0 ): main [ 0 ] - [ 6 ] -> <paragraph>' );
  395. delta.log();
  396. expect( log.calledWithExactly( delta.toString() ) ).to.be.true;
  397. } );
  398. } );
  399. it( 'for applied operations', () => {
  400. const delta = new InsertDelta();
  401. const op = new InsertOperation( ModelPosition.createAt( modelRoot, 0 ), [ new ModelText( 'foo' ) ], 0 );
  402. delta.addOperation( op );
  403. modelDoc.applyOperation( op );
  404. expect( log.calledWithExactly( 'Applying InsertOperation( 0 ): #foo -> main [ 0 ]' ) ).to.be.true;
  405. } );
  406. } );
  407. describe( 'should provide tree printing tools', () => {
  408. it( 'for model', () => {
  409. const modelDoc = new ModelDocument();
  410. const modelRoot = modelDoc.createRoot();
  411. modelRoot.appendChildren( [
  412. new ModelElement( 'paragraph', { foo: 'bar' }, [
  413. new ModelText( 'This is ' ), new ModelText( 'bold', { bold: true } ), new ModelText( '.' )
  414. ] ),
  415. new ModelElement( 'listItem', { type: 'numbered', indent: 0 }, new ModelText( 'One.' ) ),
  416. ] );
  417. const modelRootTree = modelRoot.printTree();
  418. expect( modelRootTree ).to.equal(
  419. '<main>' +
  420. '\n\t<paragraph foo="bar">' +
  421. '\n\t\tThis is ' +
  422. '\n\t\t<$text bold=true>bold</$text>' +
  423. '\n\t\t.' +
  424. '\n\t</paragraph>' +
  425. '\n\t<listItem type="numbered" indent=0>' +
  426. '\n\t\tOne.' +
  427. '\n\t</listItem>' +
  428. '\n</main>'
  429. );
  430. modelRoot.logTree();
  431. expect( log.calledWithExactly( modelRootTree ) ).to.be.true;
  432. const modelParagraph = modelRoot.getChild( 0 );
  433. const modelParagraphTree = modelParagraph.printTree();
  434. expect( modelParagraphTree ).to.equal(
  435. '<paragraph foo="bar">' +
  436. '\n\tThis is ' +
  437. '\n\t<$text bold=true>bold</$text>' +
  438. '\n\t.' +
  439. '\n</paragraph>'
  440. );
  441. log.reset();
  442. modelParagraph.logTree();
  443. expect( log.calledWithExactly( modelParagraphTree ) ).to.be.true;
  444. const modelDocFrag = new ModelDocumentFragment( [
  445. new ModelText( 'This is ' ), new ModelText( 'bold', { bold: true } ), new ModelText( '.' ),
  446. new ModelElement( 'paragraph', { foo: 'bar' }, [
  447. new ModelText( 'This is ' ), new ModelText( 'bold', { bold: true } ), new ModelText( '.' )
  448. ] )
  449. ] );
  450. const modelDocFragTree = modelDocFrag.printTree();
  451. expect( modelDocFragTree ).to.equal(
  452. 'ModelDocumentFragment: [' +
  453. '\n\tThis is ' +
  454. '\n\t<$text bold=true>bold</$text>' +
  455. '\n\t.' +
  456. '\n\t<paragraph foo="bar">' +
  457. '\n\t\tThis is ' +
  458. '\n\t\t<$text bold=true>bold</$text>' +
  459. '\n\t\t.' +
  460. '\n\t</paragraph>' +
  461. '\n]'
  462. );
  463. log.reset();
  464. modelDocFrag.logTree();
  465. expect( log.calledWithExactly( modelDocFragTree ) ).to.be.true;
  466. } );
  467. it( 'for view', () => {
  468. const viewDoc = new ViewDocument();
  469. const viewRoot = viewDoc.createRoot( 'div' );
  470. viewRoot.appendChildren( [
  471. new ViewContainerElement( 'p', { foo: 'bar' }, [
  472. new ViewText( 'This is ' ), new ViewAttributeElement( 'b', null, new ViewText( 'bold' ) ), new ViewText( '.' )
  473. ] ),
  474. new ViewContainerElement( 'ol', null, [
  475. new ViewContainerElement( 'li', null, new ViewText( 'One.' ) )
  476. ] )
  477. ] );
  478. const viewRootTree = viewRoot.printTree();
  479. expect( viewRootTree ).to.equal(
  480. '<div>' +
  481. '\n\t<p foo="bar">' +
  482. '\n\t\tThis is ' +
  483. '\n\t\t<b>' +
  484. '\n\t\t\tbold' +
  485. '\n\t\t</b>' +
  486. '\n\t\t.' +
  487. '\n\t</p>' +
  488. '\n\t<ol>' +
  489. '\n\t\t<li>' +
  490. '\n\t\t\tOne.' +
  491. '\n\t\t</li>' +
  492. '\n\t</ol>' +
  493. '\n</div>'
  494. );
  495. viewRoot.logTree();
  496. expect( log.calledWithExactly( viewRootTree ) ).to.be.true;
  497. const viewParagraph = viewRoot.getChild( 0 );
  498. const viewParagraphTree = viewParagraph.printTree();
  499. expect( viewParagraphTree ).to.equal(
  500. '<p foo="bar">' +
  501. '\n\tThis is ' +
  502. '\n\t<b>' +
  503. '\n\t\tbold' +
  504. '\n\t</b>' +
  505. '\n\t.' +
  506. '\n</p>'
  507. );
  508. log.reset();
  509. viewParagraph.logTree();
  510. expect( log.calledWithExactly( viewParagraphTree ) ).to.be.true;
  511. const viewDocFrag = new ViewDocumentFragment( [
  512. new ViewText( 'Text.' ),
  513. new ViewContainerElement( 'p', { foo: 'bar' }, [
  514. new ViewText( 'This is ' ), new ViewAttributeElement( 'b', null, new ViewText( 'bold' ) ), new ViewText( '.' )
  515. ] )
  516. ] );
  517. const viewDocFragTree = viewDocFrag.printTree();
  518. expect( viewDocFragTree ).to.equal(
  519. 'ViewDocumentFragment: [' +
  520. '\n\tText.' +
  521. '\n\t<p foo="bar">' +
  522. '\n\t\tThis is ' +
  523. '\n\t\t<b>' +
  524. '\n\t\t\tbold' +
  525. '\n\t\t</b>' +
  526. '\n\t\t.' +
  527. '\n\t</p>' +
  528. '\n]'
  529. );
  530. log.reset();
  531. viewDocFrag.logTree();
  532. expect( log.calledWithExactly( viewDocFragTree ) ).to.be.true;
  533. } );
  534. } );
  535. describe( 'should store model and view trees state', () => {
  536. let editor;
  537. beforeEach( () => {
  538. const div = document.createElement( 'div' );
  539. return TestEditor.create( div, {
  540. plugins: [ DebugPlugin ]
  541. } ).then( _editor => {
  542. editor = _editor;
  543. } );
  544. } );
  545. it( 'should store model and view state after each applied operation', () => {
  546. const model = editor.document;
  547. const modelRoot = model.getRoot();
  548. const view = editor.editing.view;
  549. const insert = new InsertOperation( ModelPosition.createAt( modelRoot, 0 ), new ModelText( 'foobar' ), 0 );
  550. model.applyOperation( wrapInDelta( insert ) );
  551. const graveyard = model.graveyard;
  552. const remove = new RemoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( graveyard, 0 ), 1 );
  553. model.applyOperation( wrapInDelta( remove ) );
  554. log.reset();
  555. model.log( 0 );
  556. expectLog(
  557. '<$graveyard></$graveyard>' +
  558. '\n<main></main>'
  559. );
  560. model.log( 1 );
  561. expectLog(
  562. '<$graveyard></$graveyard>' +
  563. '\n<main>' +
  564. '\n\tfoobar' +
  565. '\n</main>'
  566. );
  567. model.log( 2 );
  568. expectLog(
  569. '<$graveyard>' +
  570. '\n\too' +
  571. '\n</$graveyard>' +
  572. '\n<main>' +
  573. '\n\tfbar' +
  574. '\n</main>'
  575. );
  576. model.log();
  577. expectLog(
  578. '<$graveyard>' +
  579. '\n\too' +
  580. '\n</$graveyard>' +
  581. '\n<main>' +
  582. '\n\tfbar' +
  583. '\n</main>'
  584. );
  585. view.log( 0 );
  586. expectLog(
  587. '<div></div>'
  588. );
  589. view.log( 1 );
  590. expectLog(
  591. '<div>' +
  592. '\n\tfoobar' +
  593. '\n</div>'
  594. );
  595. view.log( 2 );
  596. expectLog(
  597. '<div>' +
  598. '\n\tfbar' +
  599. '\n</div>'
  600. );
  601. sinon.spy( model, 'log' );
  602. sinon.spy( view, 'log' );
  603. editor.logModel( 1 );
  604. expect( model.log.calledWithExactly( 1 ) ).to.be.true;
  605. editor.logView( 2 );
  606. expect( view.log.calledWithExactly( 2 ) ).to.be.true;
  607. model.log.reset();
  608. view.log.reset();
  609. editor.logModel();
  610. expect( model.log.calledWithExactly( 2 ) ).to.be.true;
  611. model.log.reset();
  612. view.log.reset();
  613. editor.logDocuments();
  614. expect( model.log.calledWithExactly( 2 ) ).to.be.true;
  615. expect( view.log.calledWithExactly( 2 ) ).to.be.true;
  616. model.log.reset();
  617. view.log.reset();
  618. editor.logDocuments( 1 );
  619. expect( model.log.calledWithExactly( 1 ) ).to.be.true;
  620. expect( view.log.calledWithExactly( 1 ) ).to.be.true;
  621. } );
  622. it( 'should remove old states', () => {
  623. const model = editor.document;
  624. const modelRoot = model.getRoot();
  625. for ( let i = 0; i < 25; i++ ) {
  626. const insert = new InsertOperation( ModelPosition.createAt( modelRoot, 0 ), new ModelText( 'foobar' ), model.version );
  627. model.applyOperation( wrapInDelta( insert ) );
  628. }
  629. model.log( 0 );
  630. expectLog( 'Tree log unavailable for given version: 0' );
  631. } );
  632. } );
  633. describe( 'should provide methods for delta replayer', () => {
  634. it( 'getAppliedDeltas()', () => {
  635. const modelDoc = new ModelDocument();
  636. expect( modelDoc.getAppliedDeltas() ).to.equal( '' );
  637. const otherRoot = modelDoc.createRoot( '$root', 'otherRoot' );
  638. const firstEle = new ModelElement( 'paragraph' );
  639. const removedEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  640. otherRoot.appendChildren( [ firstEle, removedEle ] );
  641. const delta = new MergeDelta();
  642. const graveyard = modelDoc.graveyard;
  643. const move = new MoveOperation( ModelPosition.createAt( removedEle, 0 ), 3, ModelPosition.createAt( firstEle, 0 ), 0 );
  644. const remove = new RemoveOperation( ModelPosition.createBefore( removedEle ), 1, ModelPosition.createAt( graveyard, 0 ), 1 );
  645. delta.addOperation( move );
  646. delta.addOperation( remove );
  647. modelDoc.applyOperation( move );
  648. modelDoc.applyOperation( remove );
  649. const stringifiedDeltas = modelDoc.getAppliedDeltas();
  650. expect( stringifiedDeltas ).to.equal( JSON.stringify( delta.toJSON() ) );
  651. } );
  652. it( 'createReplayer()', () => {
  653. const modelDoc = new ModelDocument();
  654. const otherRoot = modelDoc.createRoot( '$root', 'otherRoot' );
  655. const firstEle = new ModelElement( 'paragraph' );
  656. const removedEle = new ModelElement( 'paragraph', null, [ new ModelText( 'foo' ) ] );
  657. otherRoot.appendChildren( [ firstEle, removedEle ] );
  658. const delta = new MergeDelta();
  659. const graveyard = modelDoc.graveyard;
  660. const move = new MoveOperation( ModelPosition.createAt( removedEle, 0 ), 3, ModelPosition.createAt( firstEle, 0 ), 0 );
  661. const remove = new RemoveOperation( ModelPosition.createBefore( removedEle ), 1, ModelPosition.createAt( graveyard, 0 ), 1 );
  662. delta.addOperation( move );
  663. delta.addOperation( remove );
  664. const stringifiedDeltas = JSON.stringify( delta.toJSON() );
  665. const deltaReplayer = modelDoc.createReplayer( stringifiedDeltas );
  666. expect( deltaReplayer.getDeltasToReplay() ).to.deep.equal( [ JSON.parse( stringifiedDeltas ) ] );
  667. } );
  668. } );
  669. describe( 'should provide debug tools for delta transformation', () => {
  670. let document, root, otherRoot;
  671. beforeEach( () => {
  672. document = new ModelDocument();
  673. root = document.createRoot();
  674. otherRoot = document.createRoot( 'other', 'other' );
  675. } );
  676. it( 'Delta#_saveHistory()', () => {
  677. const insertDeltaA = new InsertDelta();
  678. const insertOpA = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  679. insertDeltaA.addOperation( insertOpA );
  680. const insertDeltaB = new InsertDelta();
  681. const insertOpB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  682. insertDeltaB.addOperation( insertOpB );
  683. const insertDeltaFinalA = new InsertDelta();
  684. const insertOpFinalA = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 1 );
  685. insertDeltaFinalA.addOperation( insertOpFinalA );
  686. const insertDeltaFinalAJsonWithoutHistory = JSON.stringify( insertDeltaFinalA );
  687. insertDeltaFinalA._saveHistory( {
  688. before: insertDeltaA,
  689. transformedBy: insertDeltaB,
  690. wasImportant: true,
  691. resultIndex: 0,
  692. resultsTotal: 1
  693. } );
  694. const insertDeltaC = new InsertDelta();
  695. const insertOpC = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 1 );
  696. insertDeltaC.addOperation( insertOpC );
  697. const insertDeltaFinalB = new InsertDelta();
  698. const insertOpFinalB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 2 );
  699. insertDeltaFinalB.addOperation( insertOpFinalB );
  700. insertDeltaFinalB._saveHistory( {
  701. before: insertDeltaFinalA,
  702. transformedBy: insertDeltaC,
  703. wasImportant: false,
  704. resultIndex: 1,
  705. resultsTotal: 3
  706. } );
  707. expect( insertDeltaA.history ).to.be.undefined;
  708. expect( insertDeltaB.history ).to.be.undefined;
  709. expect( insertDeltaFinalA.history ).not.to.be.undefined;
  710. expect( insertDeltaFinalA.history.length ).to.equal( 1 );
  711. expect( insertDeltaFinalA.history[ 0 ] ).to.deep.equal( {
  712. before: JSON.stringify( insertDeltaA ),
  713. transformedBy: JSON.stringify( insertDeltaB ),
  714. wasImportant: true,
  715. resultIndex: 0,
  716. resultsTotal: 1
  717. } );
  718. expect( insertDeltaFinalB.history ).not.to.be.undefined;
  719. expect( insertDeltaFinalB.history.length ).to.equal( 2 );
  720. expect( insertDeltaFinalB.history[ 0 ] ).to.deep.equal( {
  721. before: JSON.stringify( insertDeltaA ),
  722. transformedBy: JSON.stringify( insertDeltaB ),
  723. wasImportant: true,
  724. resultIndex: 0,
  725. resultsTotal: 1
  726. } );
  727. expect( insertDeltaFinalB.history[ 1 ] ).to.deep.equal( {
  728. before: insertDeltaFinalAJsonWithoutHistory,
  729. transformedBy: JSON.stringify( insertDeltaC ),
  730. wasImportant: false,
  731. resultIndex: 1,
  732. resultsTotal: 3
  733. } );
  734. } );
  735. it( 'save delta history on deltaTransform.transform', () => {
  736. const deltaA = new MoveDelta();
  737. const opA = new MoveOperation( ModelPosition.createAt( root, 4 ), 4, ModelPosition.createAt( otherRoot, 4 ), 0 );
  738. deltaA.addOperation( opA );
  739. const deltaB = new InsertDelta();
  740. const opB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  741. deltaB.addOperation( opB );
  742. const deltaC = new MoveDelta();
  743. const opC = new MoveOperation( ModelPosition.createAt( root, 4 ), 2, ModelPosition.createAt( root, 0 ), 1 );
  744. deltaC.addOperation( opC );
  745. let result = deltaTransform.transform( deltaA, deltaB, { document, wasAffected: new Map() } );
  746. expect( result[ 0 ].history ).not.to.be.undefined;
  747. expect( result[ 0 ].history.length ).to.equal( 1 );
  748. expect( result[ 0 ].history[ 0 ] ).to.deep.equal( {
  749. before: JSON.stringify( deltaA ),
  750. transformedBy: JSON.stringify( deltaB ),
  751. wasImportant: false,
  752. resultIndex: 0,
  753. resultsTotal: 1
  754. } );
  755. const firstResultWithoutHistory = result[ 0 ].clone();
  756. delete firstResultWithoutHistory.history;
  757. result = deltaTransform.transform( result[ 0 ], deltaC, { isStrong: true, document, wasAffected: new Map() } );
  758. expect( result[ 0 ].history ).not.to.be.undefined;
  759. expect( result[ 0 ].history.length ).to.equal( 2 );
  760. expect( result[ 0 ].history[ 0 ] ).to.deep.equal( {
  761. before: JSON.stringify( deltaA ),
  762. transformedBy: JSON.stringify( deltaB ),
  763. wasImportant: false,
  764. resultIndex: 0,
  765. resultsTotal: 1
  766. } );
  767. expect( result[ 0 ].history[ 1 ] ).to.deep.equal( {
  768. before: JSON.stringify( firstResultWithoutHistory ),
  769. transformedBy: JSON.stringify( deltaC ),
  770. wasImportant: true,
  771. resultIndex: 0,
  772. resultsTotal: 2
  773. } );
  774. } );
  775. it( 'recreate delta using Delta#history', () => {
  776. const deltaA = new MoveDelta();
  777. const opA = new MoveOperation( ModelPosition.createAt( root, 4 ), 4, ModelPosition.createAt( otherRoot, 4 ), 0 );
  778. deltaA.addOperation( opA );
  779. const deltaB = new InsertDelta();
  780. const opB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  781. deltaB.addOperation( opB );
  782. const deltaC = new MoveDelta();
  783. const opC = new MoveOperation( ModelPosition.createAt( root, 4 ), 2, ModelPosition.createAt( root, 0 ), 1 );
  784. deltaC.addOperation( opC );
  785. let original = deltaTransform.transform( deltaA, deltaB, { document, wasAffected: new Map() } );
  786. original = deltaTransform.transform( original[ 0 ], deltaC, { isStrong: true, document, wasAffected: new Map() } )[ 0 ];
  787. const history = original.history;
  788. let recreated = deltaTransform.transform(
  789. DeltaFactory.fromJSON( JSON.parse( history[ 0 ].before ), document ),
  790. DeltaFactory.fromJSON( JSON.parse( history[ 0 ].transformedBy ), document ),
  791. { isStrong: history[ 0 ].wasImportant, document, wasAffected: new Map() }
  792. );
  793. recreated = recreated[ history[ 0 ].resultIndex ];
  794. recreated = deltaTransform.transform(
  795. recreated,
  796. DeltaFactory.fromJSON( JSON.parse( history[ 1 ].transformedBy ), document ),
  797. { isStrong: history[ 1 ].wasImportant, document, wasAffected: new Map() }
  798. );
  799. recreated = recreated[ history[ 1 ].resultIndex ];
  800. delete original.history;
  801. delete recreated.history;
  802. expect( JSON.stringify( recreated ) ).to.equal( JSON.stringify( original ) );
  803. } );
  804. describe( 'provide additional logging when transformation crashes', () => {
  805. it( 'with more important delta A', () => {
  806. const deltaA = new MoveDelta();
  807. const opA = new MoveOperation( ModelPosition.createAt( root, 4 ), 4, ModelPosition.createAt( otherRoot, 4 ), 0 );
  808. deltaA.addOperation( opA );
  809. const deltaB = new InsertDelta();
  810. const opB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  811. deltaB.addOperation( opB );
  812. testUtils.sinon.stub( deltaTransform, 'defaultTransform' ).throws( new Error() );
  813. expect( () => deltaTransform.transform( deltaA, deltaB, { isStrong: true } ) ).to.throw( Error );
  814. expect( error.calledWith( deltaA.toString() + ' (important)' ) ).to.be.true;
  815. expect( error.calledWith( deltaB.toString() ) ).to.be.true;
  816. } );
  817. it( 'with more important delta B', () => {
  818. const deltaA = new MoveDelta();
  819. const opA = new MoveOperation( ModelPosition.createAt( root, 4 ), 4, ModelPosition.createAt( otherRoot, 4 ), 0 );
  820. deltaA.addOperation( opA );
  821. const deltaB = new InsertDelta();
  822. const opB = new InsertOperation( ModelPosition.createAt( root, 0 ), new ModelText( 'a' ), 0 );
  823. deltaB.addOperation( opB );
  824. testUtils.sinon.stub( deltaTransform, 'defaultTransform' ).throws( new Error() );
  825. expect( () => deltaTransform.transform( deltaA, deltaB, { isStrong: false } ) ).to.throw( Error );
  826. expect( error.calledWith( deltaA.toString() ) ).to.be.true;
  827. expect( error.calledWith( deltaB.toString() + ' (important)' ) ).to.be.true;
  828. } );
  829. } );
  830. } );
  831. function expectLog( expectedLogMsg ) {
  832. expect( log.calledWithExactly( expectedLogMsg ) ).to.be.true;
  833. log.reset();
  834. }
  835. function wrapInDelta( op ) {
  836. const delta = new Delta();
  837. delta.addOperation( op );
  838. return op;
  839. }
  840. } );