Add hook function for Doc changes

This commit is contained in:
Francesco Abbate
2021-04-05 00:11:56 +02:00
parent 0dc1098705
commit d1984942ea
2 changed files with 30 additions and 14 deletions
+6 -6
View File
@@ -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