diff options
author | Guldoman <giulio.lettieri@gmail.com> | 2022-11-02 22:52:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 22:52:27 +0100 |
commit | 94f7c8b33371e49d6f026f5be6a41acd73ad9c6b (patch) | |
tree | d1599d40ea2bfa0fbaefef6083ba7ecada39f3fb /plugins/autoinsert.lua | |
parent | 00e870372f758f8e7302cc4bc612bd10d16cb6cd (diff) | |
download | lite-xl-plugins-94f7c8b33371e49d6f026f5be6a41acd73ad9c6b.tar.gz lite-xl-plugins-94f7c8b33371e49d6f026f5be6a41acd73ad9c6b.zip |
Add workaround for sorted `Doc:get_selection` issue (#141)
Diffstat (limited to 'plugins/autoinsert.lua')
-rw-r--r-- | plugins/autoinsert.lua | 14 |
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) |