From dfb64fbdf196aa85ef8b41ec279d372b15badec9 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 9 Sep 2021 15:39:41 +0200 Subject: [PATCH] Do not add selection with newlines in replace If the selected text containes newlines it doesn't make sense to use it as the initial text in the "replace text" command view. Do not use the selected text if a newline is found in the selection. Fix #511. --- data/core/commands/findreplace.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index 48cbecaf..03aa7737 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -135,7 +135,9 @@ command.add("core.docview", { end, ["find-replace:replace"] = function() - replace("Text", doc():get_text(doc():get_selection(true)), function(text, old, new) + 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) if not find_regex then return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil) end