From 6e08c3321c2770f6ecada953b9bb610fd64c58a9 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 17 May 2021 04:05:08 -0400 Subject: [PATCH] Fixed a bug where if detectindent is paired with another plugin that hooks the event, it'll overwrite the other plugin's functions. (#190) --- data/plugins/detectindent.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 681dce26..079a92e7 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -102,21 +102,28 @@ end local doc_on_text_change = Doc.on_text_change local adjust_threshold = 4 +local current_on_text_change = nil + 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_on_text_change then - Doc.on_text_change = function(self, ...) - doc_on_text_change(self, ...) + current_on_text_change = function(self, ...) update_cache(self) end elseif score >= adjust_threshold and doc_on_text_change then - Doc.on_text_change = doc_on_text_change - doc_on_text_change = nil + current_on_text_change = nil 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 function Doc:new(...)