From de5cb4fa52f50e915ff90ccfec2eafc0923dde7f Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 27 Sep 2020 15:03:01 +0100 Subject: [PATCH] Improved behaviour of `doc:join-lines` when joining to empty line --- data/core/commands/doc.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 1afd546..0a4ee42 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -160,7 +160,9 @@ local commands = { local line1, _, line2 = doc():get_selection(true) if line1 == line2 then line2 = line2 + 1 end local text = doc():get_text(line1, 1, line2, math.huge) - text = text:gsub("\n[\t ]*", " ") + text = text:gsub("(.-)\n[\t ]*", function(x) + return x:find("^%s*$") and x or x .. " " + end) doc():insert(line1, 1, text) doc():remove(line1, #text + 1, line2, math.huge) if doc():has_selection() then