From afd067219769686076d74a8e3c31290e3e4ec566 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 10 Sep 2021 14:54:55 +0200 Subject: [PATCH] Use line/col to identify selection in replace command --- data/core/commands/findreplace.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 2412c4e1..f8e8e45a 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -181,9 +181,9 @@ command.add("core.docview", { end, ["find-replace:replace"] = function() - local selected_text = doc():get_text(doc():get_selection()) - local has_newlines = selected_text:find("\n", 1, true) - replace("Text", has_newlines and "" or selected_text, function(text, old, new) + local l1, c1, l2, c2 = doc():get_selection() + local selected_text = doc():get_text(l1, c1, l2, c2) + replace("Text", l1 == l2 and selected_text or "", function(text, old, new) if not find_regex then return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil) end