|
1 | 1 | 'use strict'; |
| 2 | + |
| 3 | +const AttributeMap = require('../../static/js/AttributeMap'); |
2 | 4 | const Changeset = require('../../static/js/Changeset'); |
| 5 | +const attributes = require('../../static/js/attributes'); |
3 | 6 | const exportHtml = require('./ExportHtml'); |
4 | 7 |
|
5 | 8 | function PadDiff(pad, fromRev, toRev) { |
@@ -54,17 +57,11 @@ PadDiff.prototype._isClearAuthorship = function (changeset) { |
54 | 57 | return false; |
55 | 58 | } |
56 | 59 |
|
57 | | - const attributes = []; |
58 | | - Changeset.eachAttribNumber(changeset, (attrNum) => { |
59 | | - attributes.push(attrNum); |
60 | | - }); |
61 | | - |
62 | | - // check that this changeset uses only one attribute |
63 | | - if (attributes.length !== 1) { |
64 | | - return false; |
65 | | - } |
| 60 | + const [appliedAttribute, anotherAttribute] = |
| 61 | + attributes.attribsFromString(clearOperator.attribs, this._pad.pool); |
66 | 62 |
|
67 | | - const appliedAttribute = this._pad.pool.getAttrib(attributes[0]); |
| 63 | + // Check that the operation has exactly one attribute. |
| 64 | + if (appliedAttribute == null || anotherAttribute != null) return false; |
68 | 65 |
|
69 | 66 | // check if the applied attribute is an anonymous author attribute |
70 | 67 | if (appliedAttribute[0] !== 'author' || appliedAttribute[1] !== '') { |
@@ -376,27 +373,19 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) { |
376 | 373 | // If the text this operator applies to is only a star, |
377 | 374 | // than this is a false positive and should be ignored |
378 | 375 | if (csOp.attribs && textBank !== '*') { |
379 | | - const deletedAttrib = apool.putAttrib(['removed', true]); |
380 | | - let authorAttrib = apool.putAttrib(['author', '']); |
381 | | - const attribs = []; |
382 | | - Changeset.eachAttribNumber(csOp.attribs, (n) => { |
383 | | - const attrib = apool.getAttrib(n); |
384 | | - attribs.push(attrib); |
385 | | - if (attrib[0] === 'author') authorAttrib = n; |
386 | | - }); |
| 376 | + const attribs = AttributeMap.fromString(csOp.attribs, apool); |
387 | 377 | const undoBackToAttribs = cachedStrFunc((oldAttribsStr) => { |
388 | | - const backAttribs = []; |
| 378 | + const oldAttribs = AttributeMap.fromString(oldAttribsStr, apool); |
| 379 | + const backAttribs = new AttributeMap(apool) |
| 380 | + .set('author', '') |
| 381 | + .set('removed', 'true'); |
389 | 382 | for (const [key, value] of attribs) { |
390 | | - const oldValue = Changeset.attribsAttributeValue(oldAttribsStr, key, apool); |
391 | | - if (oldValue !== value) backAttribs.push([key, oldValue]) |
| 383 | + const oldValue = oldAttribs.get(key); |
| 384 | + if (oldValue !== value) backAttribs.set(key, oldValue); |
392 | 385 | } |
393 | | - |
394 | | - return Changeset.makeAttribsString('=', backAttribs, apool); |
| 386 | + return backAttribs.toString(); |
395 | 387 | }); |
396 | 388 |
|
397 | | - const oldAttribsAddition = |
398 | | - `*${Changeset.numToString(deletedAttrib)}*${Changeset.numToString(authorAttrib)}`; |
399 | | - |
400 | 389 | let textLeftToProcess = textBank; |
401 | 390 |
|
402 | 391 | while (textLeftToProcess.length > 0) { |
@@ -429,7 +418,7 @@ PadDiff.prototype._createDeletionChangeset = function (cs, startAText, apool) { |
429 | 418 | let textBankIndex = 0; |
430 | 419 | consumeAttribRuns(lengthToProcess, (len, attribs, endsLine) => { |
431 | 420 | // get the old attributes back |
432 | | - const oldAttribs = (undoBackToAttribs(attribs) || '') + oldAttribsAddition; |
| 421 | + const oldAttribs = undoBackToAttribs(attribs); |
433 | 422 |
|
434 | 423 | builder.insert(processText.substr(textBankIndex, len), oldAttribs); |
435 | 424 | textBankIndex += len; |
|
0 commit comments