diff --git a/cmd/micro/cellview.go b/cmd/micro/cellview.go index 0a64ed9e..1719e87f 100644 --- a/cmd/micro/cellview.go +++ b/cmd/micro/cellview.go @@ -188,6 +188,9 @@ func (c *CellView) Draw(buf *Buffer, top, height, left, width int) { } for i := top; i < top+height; i++ { + if i >= buf.NumLines { + break + } buf.SetMatch(i, nil) } } diff --git a/cmd/micro/highlight/highlighter.go b/cmd/micro/highlight/highlighter.go index fcc32626..98892348 100644 --- a/cmd/micro/highlight/highlighter.go +++ b/cmd/micro/highlight/highlighter.go @@ -94,7 +94,9 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE loc := findIndex(region.end, line, start == 0, canMatchEnd) if loc != nil { - highlights[start+loc[1]-1] = region.group + if !statesOnly { + highlights[start+loc[1]-1] = region.group + } if region.parent == nil { if !statesOnly { highlights[start+loc[1]] = 0 @@ -270,6 +272,10 @@ func (h *Highlighter) HighlightStates(input LineStates) { // This assumes that all the states are set correctly func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int) { for i := startline; i < endline; i++ { + if i >= input.LinesNum() { + break + } + line := []byte(input.Line(i)) highlights := make(LineMatch)