aboutsummaryrefslogtreecommitdiff
path: root/plugins/sort.lua
diff options
context:
space:
mode:
authorGuldoman <giulio.lettieri@gmail.com>2022-11-02 22:52:27 +0100
committerGitHub <noreply@github.com>2022-11-02 22:52:27 +0100
commit94f7c8b33371e49d6f026f5be6a41acd73ad9c6b (patch)
treed1599d40ea2bfa0fbaefef6083ba7ecada39f3fb /plugins/sort.lua
parent00e870372f758f8e7302cc4bc612bd10d16cb6cd (diff)
downloadlite-xl-plugins-94f7c8b33371e49d6f026f5be6a41acd73ad9c6b.tar.gz
lite-xl-plugins-94f7c8b33371e49d6f026f5be6a41acd73ad9c6b.zip
Add workaround for sorted `Doc:get_selection` issue (#141)
Diffstat (limited to 'plugins/sort.lua')
-rw-r--r--plugins/sort.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/plugins/sort.lua b/plugins/sort.lua
index b933bb4..899475e 100644
--- a/plugins/sort.lua
+++ b/plugins/sort.lua
@@ -3,6 +3,17 @@ local core = require "core"
local command = require "core.command"
local translate = require "core.doc.translate"
+-- 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 split_lines(text)
local res = {}
for line in (text .. "\n"):gmatch("(.-)\n") do
@@ -15,7 +26,7 @@ command.add("core.docview!", {
["sort:sort"] = function(dv)
local doc = dv.doc
- local l1, c1, l2, c2, swap = doc:get_selection(true)
+ local l1, c1, l2, c2, swap = get_selection(doc, true)
l1, c1 = translate.start_of_line(doc, l1, c1)
l2, c2 = translate.end_of_line(doc, l2, c2)
doc:set_selection(l1, c1, l2, c2, swap)