diff --git a/kittens/diff/highlight.go b/kittens/diff/highlight.go index 8bf3755e9f..a83525c664 100644 --- a/kittens/diff/highlight.go +++ b/kittens/diff/highlight.go @@ -183,6 +183,7 @@ func resolved_chroma_style() *chroma.Style { } var tokens_map map[string][]chroma.Token +var mu sync.Mutex func highlight_file(path string) (highlighted string, err error) { defer func() { @@ -210,7 +211,9 @@ func highlight_file(path string) (highlighted string, err error) { if tokens_map == nil { tokens_map = make(map[string][]chroma.Token) } + mu.Lock() tokens := tokens_map[path] + mu.Unlock() if tokens == nil { lexer := lexers.Match(filename_for_detection) if lexer == nil { @@ -225,7 +228,9 @@ func highlight_file(path string) (highlighted string, err error) { return "", err } tokens = iterator.Tokens() + mu.Lock() tokens_map[path] = tokens + mu.Unlock() } formatter := chroma.FormatterFunc(ansi_formatter) w := strings.Builder{}