Fixed a bug where if detectindent is paired with another plugin that hooks the event, it'll overwrite the other plugin's functions. (#190)

This commit is contained in:
Adam 2021-05-17 04:05:08 -04:00 committed by GitHub
parent e43f1b9df9
commit 6e08c3321c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -102,21 +102,28 @@ end
local doc_on_text_change = Doc.on_text_change local doc_on_text_change = Doc.on_text_change
local adjust_threshold = 4 local adjust_threshold = 4
local current_on_text_change = nil
local function update_cache(doc) local function update_cache(doc)
local type, size, score = detect_indent_stat(doc) local type, size, score = detect_indent_stat(doc)
cache[doc] = { type = type, size = size, confirmed = (score >= adjust_threshold) } cache[doc] = { type = type, size = size, confirmed = (score >= adjust_threshold) }
doc.indent_info = cache[doc] doc.indent_info = cache[doc]
if score < adjust_threshold and doc_on_text_change then if score < adjust_threshold and doc_on_text_change then
Doc.on_text_change = function(self, ...) current_on_text_change = function(self, ...)
doc_on_text_change(self, ...)
update_cache(self) update_cache(self)
end end
elseif score >= adjust_threshold and doc_on_text_change then elseif score >= adjust_threshold and doc_on_text_change then
Doc.on_text_change = doc_on_text_change current_on_text_change = nil
doc_on_text_change = nil
end end
end end
function Doc:on_text_change(...)
if current_on_text_change then
current_on_text_change(...)
end
doc_on_text_change(...)
end
local new = Doc.new local new = Doc.new
function Doc:new(...) function Doc:new(...)