aboutsummaryrefslogtreecommitdiff
path: root/plugins/autoinsert.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/autoinsert.lua')
-rw-r--r--plugins/autoinsert.lua14
1 files changed, 13 insertions, 1 deletions
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua
index a02b6a5..f6a8924 100644
--- a/plugins/autoinsert.lua
+++ b/plugins/autoinsert.lua
@@ -18,6 +18,18 @@ config.plugins.autoinsert = common.merge({ map = {
} }, config.plugins.autoinsert)
+-- Workaround for bug in Lite XL 2.1
+-- Remove this when b029f5993edb7dee5ccd2ba55faac1ec22e24609 is in a release
+local function get_selection(doc, sort)
+ local line1, col1, line2, col2 = doc:get_selection_idx(doc.last_selection)
+ if line1 then
+ return doc:get_selection_idx(doc.last_selection, sort)
+ else
+ return doc:get_selection_idx(1, sort)
+ end
+end
+
+
local function is_closer(chr)
for _, v in pairs(config.plugins.autoinsert.map) do
if v == chr then
@@ -47,7 +59,7 @@ function DocView:on_text_input(text)
-- wrap selection if we have a selection
if mapping and self.doc:has_selection() then
- local l1, c1, l2, c2, swap = self.doc:get_selection(true)
+ local l1, c1, l2, c2, swap = get_selection(self.doc, true)
self.doc:insert(l2, c2, mapping)
self.doc:insert(l1, c1, text)
self.doc:set_selection(l1, c1, l2, c2 + 2, swap)