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.
This commit is contained in:
Francesco Abbate 2021-09-09 15:39:41 +02:00
parent 16170e8db9
commit dfb64fbdf1
1 changed files with 3 additions and 1 deletions

View File

@ -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