mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-05 16:37:20 -04:00
Fix highlighting for regions starting in regions
This commit is contained in:
+25
-9
@@ -94,15 +94,23 @@ func (h *Highlighter) highlightRegion(start int, canMatchEnd bool, lineNum int,
|
|||||||
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], region.parent)))
|
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], region.parent)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstLoc := []int{len(line), 0}
|
||||||
|
var firstRegion *Region
|
||||||
for _, r := range region.rules.regions {
|
for _, r := range region.rules.regions {
|
||||||
loc = FindIndex(r.start, line, start == 0, canMatchEnd)
|
loc := FindIndex(r.start, line, start == 0, canMatchEnd)
|
||||||
if loc != nil {
|
if loc != nil {
|
||||||
highlights[start+loc[0]] = r.group
|
if loc[0] < firstLoc[0] {
|
||||||
return combineLineMatch(highlights,
|
firstLoc = loc
|
||||||
combineLineMatch(h.highlightRegion(start, false, lineNum, line[:loc[0]], region),
|
firstRegion = r
|
||||||
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], r)))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if firstLoc[0] != len(line) {
|
||||||
|
highlights[start+firstLoc[0]] = firstRegion.group
|
||||||
|
return combineLineMatch(highlights,
|
||||||
|
combineLineMatch(h.highlightRegion(start, false, lineNum, line[:firstLoc[0]], region),
|
||||||
|
h.highlightRegion(start+firstLoc[1], canMatchEnd, lineNum, line[firstLoc[1]:], firstRegion)))
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range region.rules.patterns {
|
for _, p := range region.rules.patterns {
|
||||||
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||||
@@ -130,15 +138,23 @@ func (h *Highlighter) highlightEmptyRegion(start int, canMatchEnd bool, lineNum
|
|||||||
return highlights
|
return highlights
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstLoc := []int{len(line), 0}
|
||||||
|
var firstRegion *Region
|
||||||
for _, r := range h.def.rules.regions {
|
for _, r := range h.def.rules.regions {
|
||||||
loc := FindIndex(r.start, line, start == 0, canMatchEnd)
|
loc := FindIndex(r.start, line, start == 0, canMatchEnd)
|
||||||
if loc != nil {
|
if loc != nil {
|
||||||
highlights[start+loc[0]] = r.group
|
if loc[0] < firstLoc[0] {
|
||||||
return combineLineMatch(highlights,
|
firstLoc = loc
|
||||||
combineLineMatch(h.highlightEmptyRegion(start, false, lineNum, line[:loc[0]]),
|
firstRegion = r
|
||||||
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], r)))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if firstLoc[0] != len(line) {
|
||||||
|
highlights[start+firstLoc[0]] = firstRegion.group
|
||||||
|
return combineLineMatch(highlights,
|
||||||
|
combineLineMatch(h.highlightEmptyRegion(start, false, lineNum, line[:firstLoc[0]]),
|
||||||
|
h.highlightRegion(start+firstLoc[1], canMatchEnd, lineNum, line[firstLoc[1]:], firstRegion)))
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range h.def.rules.patterns {
|
for _, p := range h.def.rules.patterns {
|
||||||
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||||
|
|||||||
Reference in New Issue
Block a user