8
0

basic-transformations.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/delta/basic-transformations
  7. */
  8. import deltaTransform from './transform';
  9. const addTransformationCase = deltaTransform.addTransformationCase;
  10. const defaultTransform = deltaTransform.defaultTransform;
  11. import Range from '../range';
  12. import Position from '../position';
  13. import NoOperation from '../operation/nooperation';
  14. import AttributeOperation from '../operation/attributeoperation';
  15. import InsertOperation from '../operation/insertoperation';
  16. import Delta from './delta';
  17. import AttributeDelta from './attributedelta';
  18. import InsertDelta from './insertdelta';
  19. import MarkerDelta from './markerdelta';
  20. import MergeDelta from './mergedelta';
  21. import MoveDelta from './movedelta';
  22. import SplitDelta from './splitdelta';
  23. import WeakInsertDelta from './weakinsertdelta';
  24. import WrapDelta from './wrapdelta';
  25. import UnwrapDelta from './unwrapdelta';
  26. import RenameDelta from './renamedelta';
  27. import RemoveDelta from './removedelta';
  28. import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
  29. // Provide transformations for default deltas.
  30. // Add special case for AttributeDelta x WeakInsertDelta transformation.
  31. addTransformationCase( AttributeDelta, WeakInsertDelta, ( a, b, context ) => {
  32. // If nodes are weak-inserted into attribute delta range, we need to apply changes from attribute delta on them.
  33. // So first we do the normal transformation and if this special cases happens, we will add an extra delta.
  34. const deltas = defaultTransform( a, b, context );
  35. if ( a.range.containsPosition( b.position ) ) {
  36. deltas.push( _getComplementaryAttrDelta( b, a ) );
  37. }
  38. return deltas;
  39. } );
  40. // Add special case for AttributeDelta x SplitDelta transformation.
  41. addTransformationCase( AttributeDelta, SplitDelta, ( a, b, context ) => {
  42. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  43. if ( !b.position ) {
  44. return defaultTransform( a, b, context );
  45. }
  46. const splitPosition = new Position( b.position.root, b.position.path.slice( 0, -1 ) );
  47. const deltas = defaultTransform( a, b, context );
  48. for ( const operation of a.operations ) {
  49. // If a node that has been split has it's attribute updated, we should also update attribute of
  50. // the node created during splitting.
  51. if ( operation.range.containsPosition( splitPosition ) || operation.range.start.isEqual( splitPosition ) ) {
  52. const additionalAttributeDelta = new AttributeDelta();
  53. const rangeStart = splitPosition.getShiftedBy( 1 );
  54. const rangeEnd = Position.createFromPosition( rangeStart );
  55. rangeEnd.path.push( 0 );
  56. const oldValue = b._cloneOperation.nodes.getNode( 0 ).getAttribute( operation.key );
  57. additionalAttributeDelta.addOperation( new AttributeOperation(
  58. new Range( rangeStart, rangeEnd ),
  59. operation.key,
  60. oldValue === undefined ? null : oldValue,
  61. operation.newValue,
  62. 0
  63. ) );
  64. deltas.push( additionalAttributeDelta );
  65. break;
  66. }
  67. }
  68. return deltas;
  69. } );
  70. // Add special case for InsertDelta x MergeDelta transformation.
  71. addTransformationCase( InsertDelta, MergeDelta, ( a, b, context ) => {
  72. // If insert is applied at the same position where merge happened, we reverse the merge (we treat it like it
  73. // didn't happen) and then apply the original insert operation. This is "mirrored" in MergeDelta x InsertDelta
  74. // transformation below, where we simply do not apply MergeDelta.
  75. if ( a.position.isEqual( b.position ) ) {
  76. return [
  77. b.getReversed(),
  78. a.clone()
  79. ];
  80. }
  81. return defaultTransform( a, b, context );
  82. } );
  83. function transformMarkerDelta( a, b ) {
  84. const transformedDelta = a.clone();
  85. const transformedOp = transformedDelta.operations[ 0 ];
  86. if ( transformedOp.oldRange ) {
  87. transformedOp.oldRange = transformedOp.oldRange.getTransformedByDelta( b )[ 0 ];
  88. }
  89. if ( transformedOp.newRange ) {
  90. transformedOp.newRange = transformedOp.newRange.getTransformedByDelta( b )[ 0 ];
  91. }
  92. return [ transformedDelta ];
  93. }
  94. addTransformationCase( MarkerDelta, SplitDelta, transformMarkerDelta );
  95. addTransformationCase( MarkerDelta, MergeDelta, transformMarkerDelta );
  96. addTransformationCase( MarkerDelta, WrapDelta, transformMarkerDelta );
  97. addTransformationCase( MarkerDelta, UnwrapDelta, transformMarkerDelta );
  98. addTransformationCase( MarkerDelta, MoveDelta, transformMarkerDelta );
  99. addTransformationCase( MarkerDelta, RenameDelta, transformMarkerDelta );
  100. // Add special case for MoveDelta x MergeDelta transformation.
  101. addTransformationCase( MoveDelta, MergeDelta, ( a, b, context ) => {
  102. // If move delta is supposed to move a node that has been merged, we reverse the merge (we treat it like it
  103. // didn't happen) and then apply the original move operation. This is "mirrored" in MergeDelta x MoveDelta
  104. // transformation below, where we simply do not apply MergeDelta.
  105. const operateInSameParent =
  106. a.sourcePosition.root == b.position.root &&
  107. compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'same';
  108. const mergeInsideMoveRange = a.sourcePosition.offset <= b.position.offset && a.sourcePosition.offset + a.howMany > b.position.offset;
  109. if ( operateInSameParent && mergeInsideMoveRange ) {
  110. return [
  111. b.getReversed(),
  112. a.clone()
  113. ];
  114. }
  115. return defaultTransform( a, b, context );
  116. } );
  117. // Add special case for MergeDelta x InsertDelta transformation.
  118. addTransformationCase( MergeDelta, InsertDelta, ( a, b, context ) => {
  119. // If merge is applied at the same position where we inserted a range of nodes we cancel the merge as it's results
  120. // may be unexpected and very weird. Even if we do some "magic" we don't know what really are users' expectations.
  121. if ( a.position.isEqual( b.position ) ) {
  122. return [ noDelta() ];
  123. }
  124. return defaultTransform( a, b, context );
  125. } );
  126. // Add special case for MergeDelta x MoveDelta transformation.
  127. addTransformationCase( MergeDelta, MoveDelta, ( a, b, context ) => {
  128. // If merge is applied at the position between moved nodes we cancel the merge as it's results may be unexpected and
  129. // very weird. Even if we do some "magic" we don't know what really are users' expectations.
  130. const operateInSameParent =
  131. a.position.root == b.sourcePosition.root &&
  132. compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'same';
  133. const mergeInsideMoveRange = b.sourcePosition.offset <= a.position.offset && b.sourcePosition.offset + b.howMany > a.position.offset;
  134. if ( operateInSameParent && mergeInsideMoveRange ) {
  135. return [ noDelta() ];
  136. }
  137. return defaultTransform( a, b, context );
  138. } );
  139. // Add special case for SplitDelta x SplitDelta transformation.
  140. addTransformationCase( SplitDelta, SplitDelta, ( a, b, context ) => {
  141. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  142. if ( !a.position || !b.position ) {
  143. return defaultTransform( a, b, context );
  144. }
  145. const pathA = a.position.getParentPath();
  146. const pathB = b.position.getParentPath();
  147. // The special case is for splits inside the same parent.
  148. if ( a.position.root == b.position.root && compareArrays( pathA, pathB ) == 'same' ) {
  149. const newContext = Object.assign( {}, context );
  150. // If `a` delta splits in further location, make sure that it will move some nodes by forcing it to be strong.
  151. // Similarly, if `a` splits closer, make sure that it is transformed accordingly.
  152. if ( a.position.offset != b.position.offset ) {
  153. // We need to ensure that incoming operation is strong / weak.
  154. newContext.isStrong = a.position.offset > b.position.offset;
  155. }
  156. // Then, default transformation is almost good.
  157. // We need to change insert operations offsets, though.
  158. // We will use `context.insertBefore` for this (but only if it is not set!)
  159. if ( context.insertBefore === undefined ) {
  160. newContext.insertBefore = newContext.isStrong;
  161. }
  162. return defaultTransform( a, b, newContext );
  163. }
  164. return defaultTransform( a, b, context );
  165. } );
  166. // Add special case for SplitDelta x UnwrapDelta transformation.
  167. addTransformationCase( SplitDelta, UnwrapDelta, ( a, b, context ) => {
  168. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  169. if ( !a.position ) {
  170. return defaultTransform( a, b, context );
  171. }
  172. // If incoming split delta tries to split a node that just got unwrapped, there is actually nothing to split,
  173. // so we discard that delta.
  174. if ( a.position.root == b.position.root && compareArrays( b.position.path, a.position.getParentPath() ) === 'same' ) {
  175. return [ noDelta() ];
  176. }
  177. return defaultTransform( a, b, context );
  178. } );
  179. // Add special case for SplitDelta x WrapDelta transformation.
  180. addTransformationCase( SplitDelta, WrapDelta, ( a, b, context ) => {
  181. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  182. if ( !a.position ) {
  183. return defaultTransform( a, b, context );
  184. }
  185. // If split is applied at the position between wrapped nodes, we cancel the split as it's results may be unexpected and
  186. // very weird. Even if we do some "magic" we don't know what really are users' expectations.
  187. const sameRoot = a.position.root == b.range.start.root;
  188. const operateInSameParent = sameRoot && compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'same';
  189. const splitInsideWrapRange = b.range.start.offset < a.position.offset && b.range.end.offset >= a.position.offset;
  190. if ( operateInSameParent && splitInsideWrapRange ) {
  191. return [ noDelta() ];
  192. } else if ( sameRoot && compareArrays( a.position.getParentPath(), b.range.end.getShiftedBy( -1 ).path ) === 'same' ) {
  193. // Split position is directly inside the last node from wrap range.
  194. // If that's the case, we manually change split delta so it will "target" inside the wrapping element.
  195. // By doing so we will be inserting split node right to the original node which feels natural and is a good UX.
  196. const delta = a.clone();
  197. // 1. Fix insert operation position.
  198. // Node to split is the last children of the wrapping element.
  199. // Wrapping element is the element inserted by WrapDelta (re)insert operation.
  200. // It is inserted after the wrapped range, but the wrapped range will be moved inside it.
  201. // Having this in mind, it is correct to use wrapped range start position as the position before wrapping element.
  202. const splitNodePos = Position.createFromPosition( b.range.start );
  203. // Now, `splitNodePos` points before wrapping element.
  204. // To get a position before last children of that element, we expand position's `path` member by proper offset.
  205. splitNodePos.path.push( b.howMany - 1 );
  206. // SplitDelta insert operation position should be right after the node we split.
  207. const insertPos = splitNodePos.getShiftedBy( 1 );
  208. delta._cloneOperation.position = insertPos;
  209. // 2. Fix move operation source position.
  210. // Nodes moved by SplitDelta will be moved from new position, modified by WrapDelta.
  211. // To obtain that new position, `splitNodePos` will be used, as this is the node we are extracting children from.
  212. const sourcePos = Position.createFromPosition( splitNodePos );
  213. // Nothing changed inside split node so it is correct to use the original split position offset.
  214. sourcePos.path.push( a.position.offset );
  215. delta._moveOperation.sourcePosition = sourcePos;
  216. // 3. Fix move operation target position.
  217. // SplitDelta move operation target position should be inside the node inserted by operation above.
  218. // Since the node is empty, we will insert at offset 0.
  219. const targetPos = Position.createFromPosition( insertPos );
  220. targetPos.path.push( 0 );
  221. delta._moveOperation.targetPosition = targetPos;
  222. return [ delta ];
  223. }
  224. return defaultTransform( a, b, context );
  225. } );
  226. // Add special case for SplitDelta x WrapDelta transformation.
  227. addTransformationCase( SplitDelta, AttributeDelta, ( a, b, context ) => {
  228. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  229. if ( !a.position ) {
  230. return defaultTransform( a, b, context );
  231. }
  232. a = a.clone();
  233. const splitPosition = new Position( a.position.root, a.position.path.slice( 0, -1 ) );
  234. if ( a._cloneOperation instanceof InsertOperation ) {
  235. // If element to split had it's attribute changed, we have to reflect this change in an element
  236. // that is in SplitDelta's InsertOperation.
  237. for ( const operation of b.operations ) {
  238. if ( operation.range.containsPosition( splitPosition ) || operation.range.start.isEqual( splitPosition ) ) {
  239. if ( operation.newValue !== null ) {
  240. a._cloneOperation.nodes.getNode( 0 ).setAttribute( operation.key, operation.newValue );
  241. } else {
  242. a._cloneOperation.nodes.getNode( 0 ).removeAttribute( operation.key );
  243. }
  244. break;
  245. }
  246. }
  247. }
  248. return [ a ];
  249. } );
  250. // Add special case for UnwrapDelta x SplitDelta transformation.
  251. addTransformationCase( UnwrapDelta, SplitDelta, ( a, b, context ) => {
  252. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  253. if ( !b.position ) {
  254. return defaultTransform( a, b, context );
  255. }
  256. // If incoming unwrap delta tries to unwrap node that got split we should unwrap the original node and the split copy.
  257. // This can be achieved either by reverting split and applying unwrap to singular node, or creating additional unwrap delta.
  258. if ( a.position.root == b.position.root && compareArrays( a.position.path, b.position.getParentPath() ) === 'same' ) {
  259. return [
  260. b.getReversed(),
  261. a.clone()
  262. ];
  263. }
  264. return defaultTransform( a, b, context );
  265. } );
  266. // Add special case for WeakInsertDelta x AttributeDelta transformation.
  267. addTransformationCase( WeakInsertDelta, AttributeDelta, ( a, b ) => {
  268. // If nodes are weak-inserted into attribute delta range, we need to apply changes from attribute delta on them.
  269. const deltas = [ a.clone() ];
  270. if ( b.range.containsPosition( a.position ) ) {
  271. deltas.push( _getComplementaryAttrDelta( a, b ) );
  272. }
  273. return deltas;
  274. } );
  275. // Add special case for WrapDelta x SplitDelta transformation.
  276. addTransformationCase( WrapDelta, SplitDelta, ( a, b, context ) => {
  277. // Do not apply special transformation case if `SplitDelta` has `NoOperation` as the second operation.
  278. if ( !b.position ) {
  279. return defaultTransform( a, b, context );
  280. }
  281. // If incoming wrap delta tries to wrap range that contains split position, we have to cancel the split and apply
  282. // the wrap. Since split was already applied, we have to revert it.
  283. const sameRoot = a.range.start.root == b.position.root;
  284. const operateInSameParent = sameRoot && compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'same';
  285. const splitInsideWrapRange = a.range.start.offset < b.position.offset && a.range.end.offset >= b.position.offset;
  286. if ( operateInSameParent && splitInsideWrapRange ) {
  287. return [
  288. b.getReversed(),
  289. a.clone()
  290. ];
  291. } else if ( sameRoot && compareArrays( b.position.getParentPath(), a.range.end.getShiftedBy( -1 ).path ) === 'same' ) {
  292. const delta = a.clone();
  293. // Move wrapping element insert position one node further so it is after the split node insertion.
  294. delta._insertOperation.position.offset++;
  295. // Include the split node copy.
  296. delta._moveOperation.howMany++;
  297. // Change the path to wrapping element in move operation.
  298. delta._moveOperation.targetPosition.path[ delta._moveOperation.targetPosition.path.length - 2 ]++;
  299. return [ delta ];
  300. }
  301. return defaultTransform( a, b, context );
  302. } );
  303. // Add special case for RenameDelta x SplitDelta transformation.
  304. addTransformationCase( RenameDelta, SplitDelta, ( a, b, context ) => {
  305. const undoMode = context.aWasUndone || context.bWasUndone;
  306. // The "clone operation" may be `InsertOperation`, `ReinsertOperation`, `MoveOperation` or `NoOperation`.
  307. // `MoveOperation` has `targetPosition` which we want to use. `NoOperation` has no `position` and we don't use special case then.
  308. let insertPosition = b._cloneOperation.position || b._cloneOperation.targetPosition;
  309. if ( insertPosition ) {
  310. insertPosition = insertPosition.getShiftedBy( -1 );
  311. }
  312. const deltas = defaultTransform( a, b, context );
  313. if ( insertPosition && !undoMode && a.operations[ 0 ].position.isEqual( insertPosition ) ) {
  314. // If a node that has been split has it's name changed, we should also change name of
  315. // the node created during splitting.
  316. const additionalRenameDelta = a.clone();
  317. additionalRenameDelta.operations[ 0 ].position = insertPosition.getShiftedBy( 1 );
  318. deltas.push( additionalRenameDelta );
  319. }
  320. return deltas;
  321. } );
  322. // Add special case for SplitDelta x RenameDelta transformation.
  323. addTransformationCase( SplitDelta, RenameDelta, ( a, b, context ) => {
  324. const undoMode = context.aWasUndone || context.bWasUndone;
  325. // The "clone operation" may be `InsertOperation`, `ReinsertOperation`, `MoveOperation` or `NoOperation`.
  326. // `MoveOperation` has `targetPosition` which we want to use. `NoOperation` has no `position` and we don't use special case then.
  327. let insertPosition = a._cloneOperation.position || a._cloneOperation.targetPosition;
  328. if ( insertPosition ) {
  329. insertPosition = insertPosition.getShiftedBy( -1 );
  330. }
  331. // If element to split had it's name changed, we have to reflect this by creating additional rename operation.
  332. if ( insertPosition && !undoMode && b.operations[ 0 ].position.isEqual( insertPosition ) ) {
  333. const additionalRenameDelta = b.clone();
  334. additionalRenameDelta.operations[ 0 ].position = insertPosition.getShiftedBy( 1 );
  335. // `nodes` is a property that is available only if `SplitDelta` `a` has `InsertOperation`.
  336. // `SplitDelta` may have `ReinsertOperation` instead of `InsertOperation`.
  337. // However, such delta is only created when `MergeDelta` is reversed.
  338. // So if this is not undo mode, it means that `SplitDelta` has `InsertOperation`.
  339. additionalRenameDelta.operations[ 0 ].oldName = a._cloneOperation.nodes.getNode( 0 ).name;
  340. return [ a.clone(), additionalRenameDelta ];
  341. }
  342. return [ a.clone() ];
  343. } );
  344. // Add special case for RemoveDelta x SplitDelta transformation.
  345. addTransformationCase( RemoveDelta, SplitDelta, ( a, b, context ) => {
  346. const deltas = defaultTransform( a, b, context );
  347. // The "clone operation" may be InsertOperation, ReinsertOperation, MoveOperation or NoOperation.
  348. const insertPosition = b._cloneOperation.position || b._cloneOperation.targetPosition;
  349. // NoOperation.
  350. if ( !insertPosition ) {
  351. return defaultTransform( a, b, context );
  352. }
  353. // In case if `defaultTransform` returned more than one delta.
  354. for ( const delta of deltas ) {
  355. // "No delta" may be returned in some cases.
  356. if ( delta instanceof RemoveDelta ) {
  357. const operation = delta._moveOperation;
  358. const rangeEnd = operation.sourcePosition.getShiftedBy( operation.howMany );
  359. if ( rangeEnd.isEqual( insertPosition ) ) {
  360. operation.howMany += 1;
  361. }
  362. }
  363. }
  364. return deltas;
  365. } );
  366. // Add special case for SplitDelta x RemoveDelta transformation.
  367. addTransformationCase( SplitDelta, RemoveDelta, ( a, b, context ) => {
  368. // This case is very trickily solved.
  369. // Instead of fixing `a` delta, we change `b` delta for a while and fire default transformation with fixed `b` delta.
  370. // Thanks to that fixing `a` delta will be differently (correctly) transformed.
  371. //
  372. // The "clone operation" may be InsertOperation, ReinsertOperation, MoveOperation or NoOperation.
  373. const insertPosition = a._cloneOperation.position || a._cloneOperation.targetPosition;
  374. // NoOperation.
  375. if ( !insertPosition ) {
  376. return defaultTransform( a, b, context );
  377. }
  378. b = b.clone();
  379. const operation = b._moveOperation;
  380. const rangeEnd = operation.sourcePosition.getShiftedBy( operation.howMany );
  381. if ( rangeEnd.isEqual( insertPosition ) ) {
  382. operation.howMany += 1;
  383. }
  384. return defaultTransform( a, b, context );
  385. } );
  386. // Helper function for `AttributeDelta` class transformations.
  387. // Creates an attribute delta that sets attribute from given `attributeDelta` on nodes from given `weakInsertDelta`.
  388. function _getComplementaryAttrDelta( weakInsertDelta, attributeDelta ) {
  389. const complementaryAttrDelta = new AttributeDelta();
  390. const nodes = weakInsertDelta.nodes;
  391. // At the beginning we store the attribute value from the first node on `weakInsertDelta` node list.
  392. let val = nodes.getNode( 0 ).getAttribute( attributeDelta.key );
  393. // This stores the last index of `weakInsertDelta` node list where the attribute value was different
  394. // than in the previous node. We need it to create separate `AttributeOperation`s for nodes with different attributes.
  395. let lastOffset = 0;
  396. // Sum of offsets of already processed nodes.
  397. let offsetSum = nodes.getNode( 0 ).offsetSize;
  398. for ( let i = 1; i < nodes.length; i++ ) {
  399. const node = nodes.getNode( i );
  400. const nodeAttrVal = node.getAttribute( attributeDelta.key );
  401. // If previous node has different attribute value, we will create an operation to the point before current node.
  402. // So all nodes with the same attributes up to this point will be included in one `AttributeOperation`.
  403. if ( nodeAttrVal != val ) {
  404. // New operation is created only when it is needed. If given node already has proper value for this
  405. // attribute we simply skip it without adding a new operation.
  406. if ( val != attributeDelta.value ) {
  407. addOperation();
  408. }
  409. val = nodeAttrVal;
  410. lastOffset = offsetSum;
  411. }
  412. offsetSum = offsetSum + node.offsetSize;
  413. }
  414. // At the end we have to add additional `AttributeOperation` for the last part of node list. If all nodes on the
  415. // node list had same attributes, this will be the only operation added to the delta.
  416. addOperation();
  417. return complementaryAttrDelta;
  418. function addOperation() {
  419. const range = new Range(
  420. weakInsertDelta.position.getShiftedBy( lastOffset ),
  421. weakInsertDelta.position.getShiftedBy( offsetSum )
  422. );
  423. const attrOperation = new AttributeOperation( range, attributeDelta.key, val, attributeDelta.value, 0 );
  424. complementaryAttrDelta.addOperation( attrOperation );
  425. }
  426. }
  427. // This is "no-op" delta, it has no type and only no-operation, it basically does nothing.
  428. // It is used when we don't want to apply changes but still we need to return a delta.
  429. function noDelta() {
  430. const noDelta = new Delta();
  431. // BaseVersion will be fixed later anyway.
  432. noDelta.addOperation( new NoOperation( 0 ) );
  433. return noDelta;
  434. }