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/selectionhighlight.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/selectionhighlight.lua')
-rw-r--r-- | plugins/selectionhighlight.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua index 133dced..f9bb01e 100644 --- a/plugins/selectionhighlight.lua +++ b/plugins/selectionhighlight.lua @@ -4,6 +4,17 @@ local DocView = require "core.docview" -- originally written by luveti +-- 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 draw_box(x, y, w, h, color) local r = renderer.draw_rect local s = math.ceil(SCALE) @@ -18,7 +29,7 @@ local draw_line_body = DocView.draw_line_body function DocView:draw_line_body(line, x, y) local line_height = draw_line_body(self, line, x, y) - local line1, col1, line2, col2 = self.doc:get_selection(true) + local line1, col1, line2, col2 = get_selection(self.doc, true) if line1 == line2 and col1 ~= col2 then local selection = self.doc:get_text(line1, col1, line2, col2) if not selection:match("^%s+$") then |