Add `Highlighter:update_notify` to keep track of retokenized lines
This is helpful for plugins that need to know when a line has been retokenized.
This commit is contained in:
parent
99d328cfd7
commit
685956cbdb
|
@ -22,13 +22,21 @@ function Highlighter:new(doc)
|
||||||
else
|
else
|
||||||
local max = math.min(self.first_invalid_line + 40, self.max_wanted_line)
|
local max = math.min(self.first_invalid_line + 40, self.max_wanted_line)
|
||||||
|
|
||||||
|
local retokenized_from
|
||||||
for i = self.first_invalid_line, max do
|
for i = self.first_invalid_line, max do
|
||||||
local state = (i > 1) and self.lines[i - 1].state
|
local state = (i > 1) and self.lines[i - 1].state
|
||||||
local line = self.lines[i]
|
local line = self.lines[i]
|
||||||
if not (line and line.init_state == state and line.text == self.doc.lines[i]) then
|
if not (line and line.init_state == state and line.text == self.doc.lines[i]) then
|
||||||
|
retokenized_from = retokenized_from or i
|
||||||
self.lines[i] = self:tokenize_line(i, state)
|
self.lines[i] = self:tokenize_line(i, state)
|
||||||
|
elseif retokenized_from then
|
||||||
|
self:update_notify(retokenized_from, i - retokenized_from - 1)
|
||||||
|
retokenized_from = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if retokenized_from then
|
||||||
|
self:update_notify(retokenized_from, max - retokenized_from)
|
||||||
|
end
|
||||||
|
|
||||||
self.first_invalid_line = max + 1
|
self.first_invalid_line = max + 1
|
||||||
core.redraw = true
|
core.redraw = true
|
||||||
|
@ -71,6 +79,10 @@ function Highlighter:remove_notify(line, n)
|
||||||
common.splice(self.lines, line, n)
|
common.splice(self.lines, line, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Highlighter:update_notify(line, n)
|
||||||
|
-- plugins can hook here to be notified that lines have been retokenized
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Highlighter:tokenize_line(idx, state)
|
function Highlighter:tokenize_line(idx, state)
|
||||||
local res = {}
|
local res = {}
|
||||||
|
@ -87,6 +99,7 @@ function Highlighter:get_line(idx)
|
||||||
local prev = self.lines[idx - 1]
|
local prev = self.lines[idx - 1]
|
||||||
line = self:tokenize_line(idx, prev and prev.state)
|
line = self:tokenize_line(idx, prev and prev.state)
|
||||||
self.lines[idx] = line
|
self.lines[idx] = line
|
||||||
|
self:update_notify(idx, 0)
|
||||||
end
|
end
|
||||||
self.max_wanted_line = math.max(self.max_wanted_line, idx)
|
self.max_wanted_line = math.max(self.max_wanted_line, idx)
|
||||||
return line
|
return line
|
||||||
|
|
Loading…
Reference in New Issue