mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-08-31 14:26:27 -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)))
|
||||
}
|
||||
|
||||
firstLoc := []int{len(line), 0}
|
||||
var firstRegion *Region
|
||||
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 {
|
||||
highlights[start+loc[0]] = r.group
|
||||
return combineLineMatch(highlights,
|
||||
combineLineMatch(h.highlightRegion(start, false, lineNum, line[:loc[0]], region),
|
||||
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], r)))
|
||||
if loc[0] < firstLoc[0] {
|
||||
firstLoc = loc
|
||||
firstRegion = 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 {
|
||||
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||
@@ -130,15 +138,23 @@ func (h *Highlighter) highlightEmptyRegion(start int, canMatchEnd bool, lineNum
|
||||
return highlights
|
||||
}
|
||||
|
||||
firstLoc := []int{len(line), 0}
|
||||
var firstRegion *Region
|
||||
for _, r := range h.def.rules.regions {
|
||||
loc := FindIndex(r.start, line, start == 0, canMatchEnd)
|
||||
if loc != nil {
|
||||
highlights[start+loc[0]] = r.group
|
||||
return combineLineMatch(highlights,
|
||||
combineLineMatch(h.highlightEmptyRegion(start, false, lineNum, line[:loc[0]]),
|
||||
h.highlightRegion(start+loc[1], canMatchEnd, lineNum, line[loc[1]:], r)))
|
||||
if loc[0] < firstLoc[0] {
|
||||
firstLoc = loc
|
||||
firstRegion = 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 {
|
||||
matches := FindAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||
|
||||
Reference in New Issue
Block a user