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:
parent
16170e8db9
commit
dfb64fbdf1
|
@ -135,7 +135,9 @@ command.add("core.docview", {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["find-replace:replace"] = function()
|
["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
|
if not find_regex then
|
||||||
return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil)
|
return text:gsub(old:gsub("%W", "%%%1"), new:gsub("%%", "%%%%"), nil)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue