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

Method findRangesForTextAttribute

src/trix/models/document.js:668–694  ·  view source on GitHub ↗
(attributeName, { withValue } = {})

Source from the content-addressed store, hash-verified

666 }
667
668 findRangesForTextAttribute(attributeName, { withValue } = {}) {
669 let position = 0
670 let range = []
671 const ranges = []
672
673 const match = function(piece) {
674 if (withValue) {
675 return piece.getAttribute(attributeName) === withValue
676 } else {
677 return piece.hasAttribute(attributeName)
678 }
679 }
680
681 this.getPieces().forEach((piece) => {
682 const length = piece.getLength()
683 if (match(piece)) {
684 if (range[1] === position) {
685 range[1] = position + length
686 } else {
687 ranges.push(range = [ position, position + length ])
688 }
689 }
690 position += length
691 })
692
693 return ranges
694 }
695
696 locationFromPosition(position) {
697 const location = this.blockList.findIndexAndOffsetAtPosition(Math.max(0, position))

Callers 3

findRangesOfPiecesMethod · 0.80
document_test.jsFile · 0.80
findRangesOfPiecesMethod · 0.80

Calls 2

getPiecesMethod · 0.95
getLengthMethod · 0.45

Tested by

no test coverage detected