aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-10-01 21:43:33 +0100
committerrxi <rxi@users.noreply.github.com>2020-10-01 21:43:33 +0100
commitde4227d55a5c821e3450554c952dfb3b1b192266 (patch)
treee23c74c7736fa1ace2d4cf69478344901b85f844
parentfb6e446c1b94da9d30e846b1202712f4bf38217f (diff)
downloadlite-xl-plugins-de4227d55a5c821e3450554c952dfb3b1b192266.tar.gz
lite-xl-plugins-de4227d55a5c821e3450554c952dfb3b1b192266.zip
Updated autoinsert plugin
-rw-r--r--plugins/autoinsert.lua14
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)