Skip to content

Commit

Permalink
Improved behaviour of doc:join-lines when joining to empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
rxi committed Sep 27, 2020
1 parent 878c94a commit de5cb4f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion data/core/commands/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de5cb4f

Please sign in to comment.