MCPcopy Create free account
hub / github.com/codeaashu/claude-code / applyBackground

Function applyBackground

src/native-ts/color-diff/index.ts:768–817  ·  view source on GitHub ↗
(h: Highlight, theme: Theme, ranges: Range[])

Source from the content-addressed store, hash-verified

766}
767
768function applyBackground(h: Highlight, theme: Theme, ranges: Range[]): void {
769 if (!h.marker) return
770 const lineBg = lineBackground(h.marker, theme)
771 const wordBg = wordBackground(h.marker, theme)
772
773 let rangeIdx = 0
774 let byteOff = 0
775 for (let li = 0; li < h.lines.length; li++) {
776 const newLine: Block[] = []
777 for (const [style, text] of h.lines[li]!) {
778 const textStart = byteOff
779 const textEnd = byteOff + text.length
780
781 while (rangeIdx < ranges.length && ranges[rangeIdx]!.end <= textStart) {
782 rangeIdx++
783 }
784 if (rangeIdx >= ranges.length) {
785 newLine.push([{ ...style, background: lineBg }, text])
786 byteOff = textEnd
787 continue
788 }
789
790 let remaining = text
791 let pos = textStart
792 while (remaining.length > 0 && rangeIdx < ranges.length) {
793 const r = ranges[rangeIdx]!
794 const inRange = pos >= r.start && pos < r.end
795 let next: number
796 if (inRange) {
797 next = Math.min(r.end, textEnd)
798 } else if (r.start > pos && r.start < textEnd) {
799 next = r.start
800 } else {
801 next = textEnd
802 }
803 const segLen = next - pos
804 const seg = remaining.slice(0, segLen)
805 newLine.push([{ ...style, background: inRange ? wordBg : lineBg }, seg])
806 remaining = remaining.slice(segLen)
807 pos = next
808 if (pos >= r.end) rangeIdx++
809 }
810 if (remaining.length > 0) {
811 newLine.push([{ ...style, background: lineBg }, remaining])
812 }
813 byteOff = textEnd
814 }
815 h.lines[li] = newLine
816 }
817}
818
819function intoLines(
820 h: Highlight,

Callers 1

renderMethod · 0.85

Calls 3

lineBackgroundFunction · 0.85
wordBackgroundFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected