(document, range)
| 89 | } |
| 90 | |
| 91 | mergeDocumentAtRange(document, range) { |
| 92 | let formattedDocument, result |
| 93 | range = normalizeRange(range) |
| 94 | const [ startPosition ] = range |
| 95 | const startLocation = this.locationFromPosition(startPosition) |
| 96 | const blockAttributes = this.getBlockAtIndex(startLocation.index).getAttributes() |
| 97 | const baseBlockAttributes = document.getBaseBlockAttributes() |
| 98 | const trailingBlockAttributes = blockAttributes.slice(-baseBlockAttributes.length) |
| 99 | |
| 100 | if (arraysAreEqual(baseBlockAttributes, trailingBlockAttributes)) { |
| 101 | const leadingBlockAttributes = blockAttributes.slice(0, -baseBlockAttributes.length) |
| 102 | formattedDocument = document.copyWithBaseBlockAttributes(leadingBlockAttributes) |
| 103 | } else { |
| 104 | formattedDocument = document.copy({ consolidateBlocks: true }).copyWithBaseBlockAttributes(blockAttributes) |
| 105 | } |
| 106 | |
| 107 | const blockCount = formattedDocument.getBlockCount() |
| 108 | const firstBlock = formattedDocument.getBlockAtIndex(0) |
| 109 | |
| 110 | if (arraysAreEqual(blockAttributes, firstBlock.getAttributes())) { |
| 111 | const firstText = firstBlock.getTextWithoutBlockBreak() |
| 112 | result = this.insertTextAtRange(firstText, range) |
| 113 | |
| 114 | if (blockCount > 1) { |
| 115 | formattedDocument = new this.constructor(formattedDocument.getBlocks().slice(1)) |
| 116 | const position = startPosition + firstText.getLength() |
| 117 | result = result.insertDocumentAtRange(formattedDocument, position) |
| 118 | } |
| 119 | } else { |
| 120 | result = this.insertDocumentAtRange(formattedDocument, range) |
| 121 | } |
| 122 | |
| 123 | return result |
| 124 | } |
| 125 | |
| 126 | insertTextAtRange(text, range) { |
| 127 | range = normalizeRange(range) |
no test coverage detected