Copy/cut whole line if selection empty
This commit is contained in:
parent
5029e2ce29
commit
93d9e61a03
|
@ -47,18 +47,27 @@ end
|
||||||
|
|
||||||
local function cut_or_copy(delete)
|
local function cut_or_copy(delete)
|
||||||
local full_text = ""
|
local full_text = ""
|
||||||
|
local text = ""
|
||||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||||
if line1 ~= line2 or col1 ~= col2 then
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
local text = doc():get_text(line1, col1, line2, col2)
|
text = doc():get_text(line1, col1, line2, col2)
|
||||||
|
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
||||||
if delete then
|
if delete then
|
||||||
doc():delete_to_cursor(idx, 0)
|
doc():delete_to_cursor(idx, 0)
|
||||||
end
|
end
|
||||||
full_text = full_text == "" and text or (full_text .. "\n" .. text)
|
|
||||||
doc().cursor_clipboard[idx] = text
|
|
||||||
else
|
else
|
||||||
doc().cursor_clipboard[idx] = ""
|
text = "\n" .. doc().lines[line1]:gsub("\n", "")
|
||||||
|
full_text = full_text == "" and text or (full_text .. text)
|
||||||
|
if delete then
|
||||||
|
if line1 < #doc().lines then
|
||||||
|
doc():remove(line1, 1, line1 + 1, 1)
|
||||||
|
else
|
||||||
|
doc():remove(line1 - 1, math.huge, line1, math.huge)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
doc().cursor_clipboard[idx] = text
|
||||||
|
end
|
||||||
doc().cursor_clipboard["full"] = full_text
|
doc().cursor_clipboard["full"] = full_text
|
||||||
system.set_clipboard(full_text)
|
system.set_clipboard(full_text)
|
||||||
end
|
end
|
||||||
|
@ -85,6 +94,13 @@ local function set_cursor(x, y, snap_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
local selection_commands = {
|
local selection_commands = {
|
||||||
|
["doc:select-none"] = function()
|
||||||
|
local line, col = doc():get_selection()
|
||||||
|
doc():set_selection(line, col)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
local commands = {
|
||||||
["doc:cut"] = function()
|
["doc:cut"] = function()
|
||||||
cut_or_copy(true)
|
cut_or_copy(true)
|
||||||
end,
|
end,
|
||||||
|
@ -93,13 +109,6 @@ local selection_commands = {
|
||||||
cut_or_copy(false)
|
cut_or_copy(false)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:select-none"] = function()
|
|
||||||
local line, col = doc():get_selection()
|
|
||||||
doc():set_selection(line, col)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local commands = {
|
|
||||||
["doc:undo"] = function()
|
["doc:undo"] = function()
|
||||||
doc():undo()
|
doc():undo()
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue