Skip to content

Commit

Permalink
highlighter: Fix last open racy access in ReHighlightStates()
Browse files Browse the repository at this point in the history
Otherwise it's possible that `ReHighlightStates()` called from the async
initial highlighting can be interrupted by the main goroutine, which then
changes the already set and furthermore used `h.lastRegion`. The resulting
last region respective set state isn't reliable any longer then.
  • Loading branch information
JoeKar committed Apr 9, 2024
1 parent acb0d76 commit aed29ee
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/highlight/highlighter.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int)
func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
// lines := input.LineData()

h.lastRegion = nil
var curState *region
if startline > 0 {
input.Lock()
if startline-1 < input.LinesNum() {
h.lastRegion = input.State(startline - 1)
curState = input.State(startline - 1)
}
input.Unlock()
}
Expand All @@ -379,12 +379,13 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
// highlights := make(LineMatch)

// var match LineMatch
h.lastRegion = curState
if i == 0 || h.lastRegion == nil {
h.highlightEmptyRegion(nil, 0, true, i, line, true)
} else {
h.highlightRegion(nil, 0, true, i, line, h.lastRegion, true)
}
curState := h.lastRegion
curState = h.lastRegion
lastState := input.State(i)

input.SetState(i, curState)
Expand Down

0 comments on commit aed29ee

Please sign in to comment.