-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
events.js
87 lines (74 loc) · 1.82 KB
/
events.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict'
document.onkeydown = function keyDown (e) {
left.last_char = e.key
// Faster than Electron
if (e.keyCode === 9) {
if (e.shiftKey) {
left.stats.nextSynonym()
} else {
left.select_autocomplete()
}
e.preventDefault()
return
}
// Faster than Electron
if (e.metaKey || e.ctrlKey) {
if (e.keyCode === 221) {
left.navi.next_marker()
e.preventDefault()
return
}
if (e.keyCode === 291) {
left.navi.prev_marker()
e.preventDefault()
return
}
}
// Reset index on space
if (e.key === ' ' || e.key === 'Enter') {
left.selection.index = 0
}
if (e.key.substring(0, 5) === 'Arrow') {
setTimeout(() => left.update(), 0) // force the refresh event to happen after the selection updates
return
}
// Slower Refresh
if (e.key === 'Enter') {
setTimeout(() => { left.dictionary.update(); left.update() }, 16)
}
}
document.onkeyup = (e) => {
if (e.keyCode === 16) { // Shift
left.stats.applySynonym()
left.update()
return
}
if (e.keyCode !== 9) {
left.update()
}
}
window.addEventListener('dragover', function (e) {
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
})
window.addEventListener('drop', function (e) {
e.stopPropagation()
e.preventDefault()
const files = e.dataTransfer.files
for (const id in files) {
const file = files[id]
if (!file.path) { continue }
if (file.type && !file.type.match(/text.*/)) { console.log(`Skipped ${file.type} : ${file.path}`); continue }
if (file.path && file.path.substr(-3, 3) === 'thm') { continue }
left.project.add(file.path)
}
left.reload()
left.navi.next_page()
})
document.onclick = function onClick (e) {
left.selection.index = 0
left.operator.stop()
left.reader.stop()
left.update()
}