forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (28 loc) · 896 Bytes
/
index.js
File metadata and controls
32 lines (28 loc) · 896 Bytes
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
const isOsx = process.platform === 'darwin'
const _normalizeAccelerator = accelerator => {
return accelerator.toLowerCase()
.replace('commandorcontrol', isOsx ? 'cmd' : 'ctrl')
.replace('cmdorctrl', isOsx ? 'cmd' : 'ctrl')
.replace('control', 'ctrl')
.replace('meta', 'cmd') // meta := cmd (macOS only) or super
.replace('command', 'cmd')
.replace('option', 'alt')
}
export const isEqualAccelerator = (a, b) => {
a = _normalizeAccelerator(a)
b = _normalizeAccelerator(b)
const i1 = a.indexOf('+')
const i2 = b.indexOf('+')
if (i1 === -1 && i2 === -1) {
return a === b
} else if (i1 === -1 || i2 === -1) {
return false
}
const partsA = a.split('+')
const partsB = b.split('+')
if (partsA.length !== partsB.length) {
return false
}
const intersection = new Set([...partsA, ...partsB])
return intersection.size === partsB.length
}