From 847ac7ee3be3d170ba76dede7455a0719062c30b Mon Sep 17 00:00:00 2001 From: redsti Date: Sun, 22 Feb 2026 16:56:45 +0100 Subject: [PATCH] fix highlighter bugs - patterns within regions no longer fail on certain line lengths and columns (#4018) - region applies patterns before next nested region --- pkg/highlight/highlighter.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/highlight/highlighter.go b/pkg/highlight/highlighter.go index a13a72610d..0302bb49ea 100644 --- a/pkg/highlight/highlighter.go +++ b/pkg/highlight/highlighter.go @@ -125,7 +125,7 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE searchNesting := true endLoc := findIndex(curRegion.end, curRegion.skip, line) if endLoc != nil { - if start == endLoc[0] { + if endLoc[0] == 0 { searchNesting = false } else { firstLoc = endLoc @@ -142,30 +142,21 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE } } } - if firstRegion != nil && firstLoc[0] != lineLen { - if !statesOnly { - highlights[start+firstLoc[0]] = firstRegion.limitGroup - } - h.highlightEmptyRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), statesOnly) - h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), firstRegion, statesOnly) - return highlights - } if !statesOnly { - fullHighlights := make([]Group, lineLen) + fullHighlights := make([]Group, firstLoc[0]) for i := 0; i < len(fullHighlights); i++ { fullHighlights[i] = curRegion.group } if searchNesting { + line_part := sliceEnd(line, firstLoc[0]) for _, p := range curRegion.rules.patterns { if curRegion.group == curRegion.limitGroup || p.group == curRegion.limitGroup { - matches := findAllIndex(p.regex, line) + matches := findAllIndex(p.regex, line_part) for _, m := range matches { - if (endLoc == nil) || (m[0] < endLoc[0]) { - for i := m[0]; i < m[1]; i++ { - fullHighlights[i] = p.group - } + for i := m[0]; i < m[1]; i++ { + fullHighlights[i] = p.group } } } @@ -178,6 +169,14 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE } } + if firstRegion != nil && firstLoc[0] != lineLen { + if !statesOnly { + highlights[start+firstLoc[0]] = firstRegion.limitGroup + } + h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), firstRegion, statesOnly) + return highlights + } + loc := endLoc if loc != nil { if !statesOnly {