Don't rehighlight if there are no modifications

This commit is contained in:
Zachary Yedidia
2020-01-28 17:15:02 -05:00
parent d965e8de4f
commit d74f40882d
3 changed files with 15 additions and 11 deletions

View File

@@ -278,7 +278,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
screen.TermMessage(err)
}
b.Modifications = make([]Loc, 10)
b.Modifications = make([]Loc, 0, 10)
OpenBuffers = append(OpenBuffers, b)
@@ -615,6 +615,7 @@ func (b *Buffer) UpdateRules() {
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
if b.Settings["syntax"].(bool) {
b.Highlighter.HighlightStates(b)
b.Highlighter.HighlightMatches(b, 0, b.End().Y)
}
}
}

View File

@@ -358,6 +358,10 @@ func (w *BufWindow) showCursor(x, y int, main bool) {
func (w *BufWindow) displayBuffer() {
b := w.Buf
if w.Height <= 0 || w.Width <= 0 {
return
}
hasMessage := len(b.Messages) > 0
bufHeight := w.Height
if w.drawStatus {
@@ -371,16 +375,12 @@ func (w *BufWindow) displayBuffer() {
if b.Settings["syntax"].(bool) && b.SyntaxDef != nil {
for _, r := range b.Modifications {
final := -1
for i := r.X; i <= r.Y; i++ {
if i > 0 && b.Rehighlight(i-1) {
b.Highlighter.ReHighlightLine(b, i-1)
b.SetRehighlight(i-1, false)
}
b.Highlighter.ReHighlightStates(b, i)
final = util.Max(b.Highlighter.ReHighlightStates(b, i), final)
}
b.Highlighter.HighlightMatches(b, r.X, final+1)
}
b.Highlighter.HighlightMatches(b, w.StartLine, w.StartLine+bufHeight)
b.ClearModifications()
}

View File

@@ -358,8 +358,9 @@ func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int)
}
// ReHighlightStates will scan down from `startline` and set the appropriate end of line state
// for each line until it comes across the same state in two consecutive lines
func (h *Highlighter) ReHighlightStates(input LineStates, startline int) {
// for each line until it comes across a line whose state does not change
// returns the number of the final line
func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
// lines := input.LineData()
h.lastRegion = nil
@@ -382,9 +383,11 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) {
input.SetState(i, curState)
if curState == lastState {
break
return i
}
}
return input.LinesNum() - 1
}
// ReHighlightLine will rehighlight the state and match for a single line