-
Notifications
You must be signed in to change notification settings - Fork 7
/
Shortcut.go
34 lines (29 loc) · 1009 Bytes
/
Shortcut.go
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
package input
import "strings"
type shortcut struct {
keyName string
modifier Modifier
key Key
}
var shortcuts = []shortcut{
{keyName: "c", modifier: ModControl, key: KeyCopy},
{keyName: "x", modifier: ModControl, key: KeyCut},
{keyName: "v", modifier: ModControl, key: KeyPaste},
{keyName: "z", modifier: ModControl, key: KeyUndo},
{keyName: "z", modifier: ModControl.With(ModShift), key: KeyRedo},
{keyName: "y", modifier: ModControl, key: KeyRedo},
{keyName: "s", modifier: ModControl, key: KeySave},
{keyName: "n", modifier: ModControl, key: KeyNew},
}
// ResolveShortcut tries to map the given name and modifier combination to a
// known (common) shortcut key. For instance, Ctrl+C is KeyCopy.
func ResolveShortcut(keyName string, modifier Modifier) (key Key, knownKey bool) {
lowercaseName := strings.ToLower(keyName)
for _, entry := range shortcuts {
if (entry.keyName == lowercaseName) && (entry.modifier == modifier) {
knownKey = true
key = entry.key
}
}
return
}