X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fhighlight%2Fhighlighter.go;h=2a7634612a70731538b9046465b1b66141daf01c;hb=342f3c223da0df38d9c4f79f4a8175c5c032adf0;hp=fdc42da3805b08c8e81b793af749825e89848f3a;hpb=3e61bd4d492a13b14f7b5dd6f35745be48236055;p=micro.git diff --git a/cmd/micro/highlight/highlighter.go b/cmd/micro/highlight/highlighter.go index fdc42da3..2a763461 100644 --- a/cmd/micro/highlight/highlighter.go +++ b/cmd/micro/highlight/highlighter.go @@ -60,7 +60,7 @@ func NewHighlighter(def *Def) *Highlighter { // color's group (represented as one byte) type LineMatch map[int]Group -func findIndex(regex *regexp.Regexp, skip []*regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int { +func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int { regexStr := regex.String() if strings.Contains(regexStr, "^") { if !canMatchStart { @@ -73,16 +73,14 @@ func findIndex(regex *regexp.Regexp, skip []*regexp.Regexp, str []rune, canMatch } } - strbytes := []byte(string(str)) - if skip != nil && len(skip) > 0 { - for _, r := range skip { - if r != nil { - strbytes = r.ReplaceAllFunc(strbytes, func(match []byte) []byte { - res := make([]byte, utf8.RuneCount(match)) - return res - }) - } - } + var strbytes []byte + if skip != nil { + strbytes = skip.ReplaceAllFunc(strbytes, func(match []byte) []byte { + res := make([]byte, utf8.RuneCount(match)) + return res + }) + } else { + strbytes = []byte(string(str)) } match := regex.FindIndex(strbytes) @@ -122,15 +120,7 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE } } - skips := make([]*regexp.Regexp, len(curRegion.rules.patterns)+1) - for i := range skips { - if i != len(skips)-1 { - skips[i] = curRegion.rules.patterns[i].regex - } else { - skips[i] = curRegion.skip - } - } - loc := findIndex(curRegion.end, skips, line, start == 0, canMatchEnd) + loc := findIndex(curRegion.end, curRegion.skip, line, start == 0, canMatchEnd) if loc != nil { if !statesOnly { highlights[start+loc[1]-1] = curRegion.group