Add hook function for Doc changes
This commit is contained in:
@@ -98,20 +98,20 @@ local function detect_indent_stat(doc)
|
||||
end
|
||||
|
||||
|
||||
local doc_text_input = Doc.text_input
|
||||
local doc_on_text_change = Doc.on_text_change
|
||||
local adjust_threshold = 4
|
||||
|
||||
local function update_cache(doc)
|
||||
local type, size, score = detect_indent_stat(doc)
|
||||
cache[doc] = { type = type, size = size, confirmed = (score >= adjust_threshold) }
|
||||
doc.indent_info = cache[doc]
|
||||
if score < adjust_threshold and Doc.text_input == doc_text_input then
|
||||
Doc.text_input = function(self, ...)
|
||||
doc_text_input(self, ...)
|
||||
if score < adjust_threshold and Doc.on_text_change == doc_on_text_change then
|
||||
Doc.on_text_change = function(self, ...)
|
||||
doc_on_text_change(self, ...)
|
||||
update_cache(self)
|
||||
end
|
||||
elseif score >= adjust_threshold and Doc.text_input ~= doc_text_input then
|
||||
Doc.text_input = doc_text_input
|
||||
elseif score >= adjust_threshold and Doc.on_text_change ~= doc_on_text_change then
|
||||
Doc.on_text_change = doc_on_text_change
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user