Copy/cut whole line if selection empty
This commit is contained in:
parent
79c4f9fcae
commit
479c58fb3d
|
@ -77,18 +77,39 @@ local commands = {
|
||||||
local text = doc():get_text(doc():get_selection())
|
local text = doc():get_text(doc():get_selection())
|
||||||
system.set_clipboard(text)
|
system.set_clipboard(text)
|
||||||
doc():delete_to(0)
|
doc():delete_to(0)
|
||||||
|
else
|
||||||
|
local line = doc():get_selection()
|
||||||
|
local text = doc().lines[line]
|
||||||
|
system.set_clipboard(text)
|
||||||
|
core.line_in_clipboard = text
|
||||||
|
if line < #doc().lines then
|
||||||
|
doc():remove(line, 1, line + 1, 1)
|
||||||
|
else
|
||||||
|
doc():remove(line - 1, math.huge, line, math.huge)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:copy"] = function()
|
["doc:copy"] = function()
|
||||||
|
local line1, col1, line2, col2, text = doc():get_selection()
|
||||||
if doc():has_selection() then
|
if doc():has_selection() then
|
||||||
local text = doc():get_text(doc():get_selection())
|
text = doc():get_text(line1, col1, line2, col2)
|
||||||
system.set_clipboard(text)
|
else
|
||||||
|
text = doc().lines[line1]
|
||||||
|
core.line_in_clipboard = text
|
||||||
end
|
end
|
||||||
|
system.set_clipboard(text)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:paste"] = function()
|
["doc:paste"] = function()
|
||||||
doc():text_input(system.get_clipboard():gsub("\r", ""))
|
local clipboard = system.get_clipboard():gsub("\r", "")
|
||||||
|
if core.line_in_clipboard == clipboard then
|
||||||
|
local line, col = doc():get_selection()
|
||||||
|
doc():insert(line, 1, clipboard)
|
||||||
|
doc():set_selection(line+1, col)
|
||||||
|
else
|
||||||
|
doc():text_input(clipboard)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:newline"] = function()
|
["doc:newline"] = function()
|
||||||
|
@ -160,9 +181,7 @@ local commands = {
|
||||||
local line1, _, line2 = doc():get_selection(true)
|
local line1, _, line2 = doc():get_selection(true)
|
||||||
if line1 == line2 then line2 = line2 + 1 end
|
if line1 == line2 then line2 = line2 + 1 end
|
||||||
local text = doc():get_text(line1, 1, line2, math.huge)
|
local text = doc():get_text(line1, 1, line2, math.huge)
|
||||||
text = text:gsub("(.-)\n[\t ]*", function(x)
|
text = text:gsub("\n[\t ]*", " ")
|
||||||
return x:find("^%s*$") and x or x .. " "
|
|
||||||
end)
|
|
||||||
doc():insert(line1, 1, text)
|
doc():insert(line1, 1, text)
|
||||||
doc():remove(line1, #text + 1, line2, math.huge)
|
doc():remove(line1, #text + 1, line2, math.huge)
|
||||||
if doc():has_selection() then
|
if doc():has_selection() then
|
||||||
|
|
Loading…
Reference in New Issue