Fixed highlighter resetting of syntax on doc filename change

This commit is contained in:
rxi 2020-05-09 16:23:07 +01:00
parent 70f62f3c8a
commit 3d49b6d200
2 changed files with 8 additions and 4 deletions

View file

@ -9,9 +9,7 @@ local Highlighter = Object:extend()
function Highlighter:new(doc) function Highlighter:new(doc)
self.doc = doc self.doc = doc
self.lines = {} self:reset()
self.first_invalid_line = 1
self.max_wanted_line = 0
-- init incremental syntax highlighting -- init incremental syntax highlighting
core.add_thread(function() core.add_thread(function()
@ -40,6 +38,12 @@ function Highlighter:new(doc)
end end
function Highlighter:reset()
self.lines = {}
self.first_invalid_line = 1
self.max_wanted_line = 0
end
function Highlighter:invalidate(idx) function Highlighter:invalidate(idx)
self.first_invalid_line = idx self.first_invalid_line = idx
self.max_wanted_line = math.min(self.max_wanted_line, #self.doc.lines) self.max_wanted_line = math.min(self.max_wanted_line, #self.doc.lines)

View file

@ -59,7 +59,7 @@ function Doc:reset_syntax()
local syn = syntax.get(self.filename or "") local syn = syntax.get(self.filename or "")
if self.syntax ~= syn then if self.syntax ~= syn then
self.syntax = syn self.syntax = syn
self.highlighter:invalidate(1) self.highlighter:reset()
end end
end end