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

Function applyBackground

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

Source from the content-addressed store, hash-verified

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

Callers 1

renderMethod · 0.85

Calls 2

lineBackgroundFunction · 0.85
wordBackgroundFunction · 0.85

Tested by

no test coverage detected