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/regexreplacepreview.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/regexreplacepreview.lua')
-rw-r--r-- | plugins/regexreplacepreview.lua | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/plugins/regexreplacepreview.lua b/plugins/regexreplacepreview.lua index dfc9e45..747e9ba 100644 --- a/plugins/regexreplacepreview.lua +++ b/plugins/regexreplacepreview.lua @@ -3,6 +3,18 @@ local core = require "core" local keymap = require "core.keymap" local command = require "core.command" +-- 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 + + -- Takes the following pattern: /pattern/replace/ -- Capture groupings can be replaced using \1 through \9 local function regex_replace_file(view, pattern, old_lines, raw, start_line, end_line) @@ -91,8 +103,8 @@ command.add("core.docview!", { ["regex-replace-preview:find-replace-regex"] = function(view) local old_lines = {} local doc = view.doc - local original_selection = { doc:get_selection(true) } - local selection = doc:has_selection() and { doc:get_selection(true) } or {} + local original_selection = { get_selection(doc, true) } + local selection = doc:has_selection() and { get_selection(doc, true) } or {} core.command_view:enter("Regex Replace (enter pattern as /old/new/)", { text = "/", submit = function(pattern) |