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/dragdropselected.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/dragdropselected.lua')
-rw-r--r-- | plugins/dragdropselected.lua | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/plugins/dragdropselected.lua b/plugins/dragdropselected.lua index 3c6583b..144c4da 100644 --- a/plugins/dragdropselected.lua +++ b/plugins/dragdropselected.lua @@ -14,6 +14,18 @@ local core = require "core" local keymap = require "core.keymap" local style = require "core.style" +-- 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 + + -- helper function for on_mouse_pressed to determine if mouse down is in selection -- iLine is line number where mouse down happened -- iCol is column where mouse down happened @@ -96,7 +108,7 @@ function DocView:on_mouse_pressed(button, x, y, clicks) -- convert pixel coordinates to line and column coordinates local iLine, iCol = self:resolve_screen_position(x, y) -- get selection coordinates - local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = self.doc:get_selection(true) + local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = get_selection(self.doc, true) -- set flag for on_mouse_released and on_mouse_moved() methods to detect dragging self.bClickedIntoSelection = isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2) |