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

Method getCommonAttributesAtPosition

src/trix/models/document.js:552–575  ·  view source on GitHub ↗
(position)

Source from the content-addressed store, hash-verified

550 }
551
552 getCommonAttributesAtPosition(position) {
553 let key, value
554 const { index, offset } = this.locationFromPosition(position)
555 const block = this.getBlockAtIndex(index)
556 if (!block) {
557 return {}
558 }
559
560 const commonAttributes = attributesForBlock(block)
561 const attributes = block.text.getAttributesAtPosition(offset)
562 const attributesLeft = block.text.getAttributesAtPosition(offset - 1)
563 const inheritableAttributes = Object.keys(config.textAttributes).filter((key) => {
564 return config.textAttributes[key].inheritable
565 })
566
567 for (key in attributesLeft) {
568 value = attributesLeft[key]
569 if (value === attributes[key] || inheritableAttributes.includes(key)) {
570 commonAttributes[key] = value
571 }
572 }
573
574 return commonAttributes
575 }
576
577 getRangeOfCommonAttributeAtPosition(attributeName, position) {
578 const { index, offset } = this.locationFromPosition(position)

Callers 1

Calls 4

locationFromPositionMethod · 0.95
getBlockAtIndexMethod · 0.95
attributesForBlockFunction · 0.85

Tested by

no test coverage detected