MCPcopy
hub / github.com/basecamp/trix / insertDocumentAtRange

Method insertDocumentAtRange

src/trix/models/document.js:72–89  ·  view source on GitHub ↗
(document, range)

Source from the content-addressed store, hash-verified

70 }
71
72 insertDocumentAtRange(document, range) {
73 const { blockList } = document
74 range = normalizeRange(range)
75 let [ position ] = range
76 const { index, offset } = this.locationFromPosition(position)
77
78 let result = this
79 const block = this.getBlockAtPosition(position)
80
81 if (rangeIsCollapsed(range) && block.isEmpty() && !block.hasAttributes()) {
82 result = new this.constructor(result.blockList.removeObjectAtIndex(index))
83 } else if (block.getBlockBreakPosition() === offset) {
84 position++
85 }
86
87 result = result.removeTextAtRange(range)
88 return new this.constructor(result.blockList.insertSplittableListAtPosition(blockList, position))
89 }
90
91 mergeDocumentAtRange(document, range) {
92 let formattedDocument, result

Callers 5

mergeDocumentAtRangeMethod · 0.95
insertDocumentMethod · 0.80
breakFormattedBlockMethod · 0.80
trix.jsFile · 0.80

Calls 10

locationFromPositionMethod · 0.95
getBlockAtPositionMethod · 0.95
normalizeRangeFunction · 0.90
rangeIsCollapsedFunction · 0.90
removeObjectAtIndexMethod · 0.80
isEmptyMethod · 0.45
hasAttributesMethod · 0.45
getBlockBreakPositionMethod · 0.45
removeTextAtRangeMethod · 0.45

Tested by

no test coverage detected