-
Notifications
You must be signed in to change notification settings - Fork 2
/
Clipboard.lua
59 lines (48 loc) · 1.5 KB
/
Clipboard.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Clipboard =
{
note_list = {}
}
function Clipboard.Cut()
if Clipboard.Copy() then
Editor.EraseNotes(App.note_list_selected[1].offset, App.note_list_selected[1].string_idx)
end
end
function Clipboard.Copy()
if #App.note_list_selected == 0 then return false; end
Util.ClearTable(Clipboard.note_list)
Clipboard.note_list = Util.CopyTable(App.note_list_selected)
table.sort(Clipboard.note_list, function (k1, k2) return k1.offset < k2.offset; end)
return true
end
function Clipboard.Paste(cx, cy)
local temp = {}
for i, v in ipairs(Clipboard.note_list) do
temp[#temp + 1] = Util.CopyNote(v)
end
local right_bound = Util.NumGridDivisions()
local src_offset = temp[1].offset
local diff = 0
local dst_offset = 0
for i, v in ipairs(temp) do
diff = v.offset - src_offset
dst_offset = cx + diff
v.offset = dst_offset
if v.offset + v.duration > right_bound then
return
end
for j, w in ipairs(App.note_list) do
if (v.string_idx == w.string_idx) and (Util.RangeOverlap(v.offset, v.offset + v.duration - 1, w.offset, w.offset + w.duration - 1)) then
return
end
end
end
Util.ClearTable(App.note_list_selected)
Util.ClearTable(App.note_list_selected.indices)
for i, v in ipairs(temp) do
App.note_list[#App.note_list + 1] = Util.CopyNote(v)
App.note_list_selected[#App.note_list_selected + 1] = Util.CopyNote(v)
App.note_list_selected.indices[#App.note_list_selected.indices + 1] = #App.note_list
end
UR.PushUndo(e_OpType.Insert, temp)
App.attempts_paste = false
end