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