diff options
Diffstat (limited to 'plugins/autoinsert.lua')
-rw-r--r-- | plugins/autoinsert.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua index 530bed6..243e00b 100644 --- a/plugins/autoinsert.lua +++ b/plugins/autoinsert.lua @@ -24,6 +24,14 @@ local function is_closer(chr) end end +local function count_char(text, chr) + local count = 0 + for _ in text:gmatch(chr) do + count = count + 1 + end + return count +end + local on_text_input = DocView.on_text_input @@ -51,6 +59,12 @@ function DocView:on_text_input(text) return end + -- don't insert closing quote if we have a non-even number on this line + local line = self.doc:get_selection() + if text == mapping and count_char(self.doc.lines[line], text) % 2 == 1 then + return on_text_input(self, text) + end + -- auto insert closing bracket if mapping and (chr:find("%s") or is_closer(chr) and chr ~= '"') then on_text_input(self, text) |