* @param {Array >} contents - where to write the result * @param {number} client * @param {number} clock * @param {boolean} deleted * @param {AbstractContent} _content * @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operati
(contents, client, clock, deleted, _content, shouldRender)
| 513 | * @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operation |
| 514 | */ |
| 515 | readContent (contents, client, clock, deleted, _content, shouldRender) { |
| 516 | const slice = (deleted ? this.deletes : this.inserts).slice(client, clock, _content.getLength()) |
| 517 | /** |
| 518 | * @type {AbstractContent?} |
| 519 | */ |
| 520 | let content = slice.length === 1 ? _content : _content.copy() |
| 521 | for (let i = 0; i < slice.length; i++) { |
| 522 | const s = slice[i] |
| 523 | if (content == null || content instanceof ContentDeleted) { |
| 524 | if ((!shouldRender && s.attrs == null) || this.inserts.has(client, s.clock)) { |
| 525 | continue |
| 526 | } |
| 527 | // Retrieved item is never more fragmented than the newer item. |
| 528 | const prevItem = getItem(this._prevDocStore, createID(client, s.clock)) |
| 529 | const diffStart = s.clock - prevItem.id.clock |
| 530 | content = prevItem.length > 1 ? prevItem.content.copy() : prevItem.content |
| 531 | // trim itemContent to the correct size. |
| 532 | if (diffStart > 0) { |
| 533 | content = content.splice(diffStart) |
| 534 | } |
| 535 | } |
| 536 | const c = /** @type {AbstractContent} */ (content) |
| 537 | const clen = c.getLength() |
| 538 | if (clen < s.len) { |
| 539 | slice.splice(i + 1, 0, createMaybeAttrRange(s.clock + clen, s.len - clen, s.attrs)) |
| 540 | s.len = clen |
| 541 | } |
| 542 | content = s.len < clen ? c.splice(s.len) : null |
| 543 | if (shouldRender || !deleted || s.attrs != null) { |
| 544 | contents.push(new AttributedContent(c, s.clock, deleted, s.attrs, shouldRender)) |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * @param {Item} item |
no test coverage detected