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

Method moveTextFromRangeToPosition

src/trix/models/document.js:188–223  ·  view source on GitHub ↗
(range, position)

Source from the content-addressed store, hash-verified

186 }
187
188 moveTextFromRangeToPosition(range, position) {
189 let text
190 range = normalizeRange(range)
191 const [ startPosition, endPosition ] = range
192 if (startPosition <= position && position <= endPosition) {
193 return this
194 }
195
196 let document = this.getDocumentAtRange(range)
197 let result = this.removeTextAtRange(range)
198
199 const movingRightward = startPosition < position
200 if (movingRightward) {
201 position -= document.getLength()
202 }
203
204 const [ firstBlock, ...blocks ] = document.getBlocks()
205 if (blocks.length === 0) {
206 text = firstBlock.getTextWithoutBlockBreak()
207 if (movingRightward) {
208 position += 1
209 }
210 } else {
211 text = firstBlock.text
212 }
213
214 result = result.insertTextAtRange(text, position)
215 if (blocks.length === 0) {
216 return result
217 }
218
219 document = new this.constructor(blocks)
220 position += text.getLength()
221
222 return result.insertDocumentAtRange(document, position)
223 }
224
225 addAttributeAtRange(attribute, value, range) {
226 let { blockList } = this

Callers

nothing calls this directly

Calls 8

getDocumentAtRangeMethod · 0.95
removeTextAtRangeMethod · 0.95
normalizeRangeFunction · 0.90
getBlocksMethod · 0.80
insertTextAtRangeMethod · 0.80
insertDocumentAtRangeMethod · 0.80
getLengthMethod · 0.45

Tested by

no test coverage detected