From 0dda252096da3c34b9f9b1eb0282c8a96a147459 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 15 Jul 2021 18:15:05 -0400 Subject: [PATCH 1/3] Reverted find fixes. --- data/core/commands/findreplace.lua | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index e5d7c70b..648c8d9e 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -10,8 +10,8 @@ local StatusView = require "core.statusview" local max_last_finds = 50 local last_finds, last_view, last_fn, last_text, last_sel -local case_insensitive = config.find_case_insensitive or false -local plain = config.find_plain or false +local case_sensitive = config.find_case_sensitive or false +local find_regex = config.find_regex or false local function doc() return last_view and last_view.doc or core.active_view.doc @@ -19,18 +19,18 @@ end local function get_find_tooltip() local rf = keymap.get_binding("find-replace:repeat-find") - local ti = keymap.get_binding("find-replace:toggle-insensitivity") - local tr = keymap.get_binding("find-replace:toggle-plain") - return (plain and "[Plain] " or "") .. - (case_insensitive and "[Insensitive] " or "") .. + local ti = keymap.get_binding("find-replace:toggle-sensitivity") + local tr = keymap.get_binding("find-replace:toggle-regex") + return (find_regex and "[Regex] " or "") .. + (case_sensitive and "[Sensitive] " or "") .. (rf and ("Press " .. rf .. " to select the next match.") or "") .. (ti and (" " .. ti .. " toggles case sensitivity.") or "") .. - (tr and (" " .. tr .. " toggles plain find.") or "") + (tr and (" " .. tr .. " toggles regex find.") or "") end local function update_preview(sel, search_fn, text) local ok, line1, col1, line2, col2 = - pcall(search_fn, last_view.doc, sel[1], sel[2], text, case_insensitive, plain) + pcall(search_fn, last_view.doc, sel[1], sel[2], text, case_sensitive, find_regex) if ok and line1 and text ~= "" then last_view.doc:set_selection(line2, col2, line1, col1) last_view:scroll_to_line(line2, true) @@ -105,15 +105,15 @@ command.add(has_selection, { command.add("core.docview", { ["find-replace:find"] = function() - find("Find Text", function(doc, line, col, text, case_insensitive, plain) - local opt = { wrap = true, no_case = case_insensitive, regex = not plain } + find("Find Text", function(doc, line, col, text, case_sensitive, find_regex) + local opt = { wrap = true, no_case = not case_sensitive, regex = find_regex } return search.find(doc, line, col, text, opt) end) end, ["find-replace:replace"] = function() replace("Text", doc():get_text(doc():get_selection(true)), function(text, old, new) - if plain then + if not find_regex then return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil) end local result, matches = regex.gsub(regex.compile(old), text, new) @@ -150,7 +150,7 @@ command.add(valid_for_finding, { core.error("No find to continue from") else local sl1, sc1, sl2, sc2 = doc():get_selection(true) - local line1, col1, line2, col2 = last_fn(doc(), sl1, sc2, last_text, case_insensitive, plain) + local line1, col1, line2, col2 = last_fn(doc(), sl1, sc2, last_text, case_sensitive, find_regex) if line1 then if last_view.doc ~= doc() then last_finds = {} @@ -177,14 +177,14 @@ command.add(valid_for_finding, { }) command.add("core.commandview", { - ["find-replace:toggle-insensitivity"] = function() - case_insensitive = not case_insensitive + ["find-replace:toggle-sensitivity"] = function() + case_sensitive = not case_sensitive core.status_view:show_tooltip(get_find_tooltip()) update_preview(last_sel, last_fn, last_text) end, - ["find-replace:toggle-plain"] = function() - plain = not plain + ["find-replace:toggle-regex"] = function() + find_regex = not find_regex core.status_view:show_tooltip(get_find_tooltip()) update_preview(last_sel, last_fn, last_text) end From a218a95c4535be0f2a507aa06e2564546e0d16dd Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 15 Jul 2021 18:21:54 -0400 Subject: [PATCH 2/3] Updated keys as well. --- data/core/keymap.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index c0d556b8..c402f37b 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -137,8 +137,8 @@ keymap.add_direct { ["ctrl+r"] = "find-replace:replace", ["f3"] = "find-replace:repeat-find", ["shift+f3"] = "find-replace:previous-find", - ["ctrl+i"] = "find-replace:toggle-insensitivity", - ["ctrl+shift+i"] = "find-replace:toggle-plain", + ["ctrl+i"] = "find-replace:toggle-sensitivity", + ["ctrl+shift+i"] = "find-replace:toggle-regex", ["ctrl+g"] = "doc:go-to-line", ["ctrl+s"] = "doc:save", ["ctrl+shift+s"] = "doc:save-as", From 6330f4d596d08314d0f89d4da47a4fe0bbb34b8d Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 15 Jul 2021 18:29:48 -0400 Subject: [PATCH 3/3] Allowed find to function across different views. --- data/core/commands/findreplace.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 648c8d9e..7904632a 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -14,7 +14,7 @@ local case_sensitive = config.find_case_sensitive or false local find_regex = config.find_regex or false local function doc() - return last_view and last_view.doc or core.active_view.doc + return core.active_view:is(DocView) and core.active_view.doc or last_view.doc end local function get_find_tooltip()