aboutsummaryrefslogtreecommitdiff
path: root/plugins/sort.lua
diff options
context:
space:
mode:
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)