-
Notifications
You must be signed in to change notification settings - Fork 27
/
keyboard.go
100 lines (96 loc) · 2.16 KB
/
keyboard.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
package nanogui
import (
"github.com/shibukawa/glfw"
"runtime"
)
type EditAction int
const (
EditActionNone EditAction = iota
EditActionMoveLeft
EditActionMoveRight
EditActionMoveLineTop
EditActionMoveLineEnd
EditActionBackspace
EditActionDelete
EditActionCutUntilLineEnd
EditActionYank
EditActionDeleteLeftWord
EditActionEnter
EditActionSelectAll
EditActionCopy
EditActionCut
EditActionPaste
)
func DetectEditAction(key glfw.Key, modifier glfw.ModifierKey) EditAction {
isMac := runtime.GOOS == "darwin"
switch key {
case glfw.KeyLeft:
return EditActionMoveLeft
case glfw.KeyB:
if modifier == glfw.ModControl {
return EditActionMoveLeft
}
case glfw.KeyRight:
return EditActionMoveRight
case glfw.KeyF:
if modifier == glfw.ModControl {
return EditActionMoveRight
}
case glfw.KeyHome:
return EditActionMoveLineTop
case glfw.KeyA:
if modifier == glfw.ModControl {
if isMac {
return EditActionMoveLineTop
} else {
return EditActionSelectAll
}
} else if modifier == glfw.ModSuper {
return EditActionSelectAll
}
case glfw.KeyEnd:
return EditActionMoveLineEnd
case glfw.KeyE:
if modifier == glfw.ModControl {
return EditActionMoveLineEnd
}
case glfw.KeyBackspace:
return EditActionBackspace
case glfw.KeyH:
if modifier == glfw.ModControl {
return EditActionBackspace
}
case glfw.KeyDelete:
if modifier == glfw.ModAlt {
return EditActionDeleteLeftWord
}
return EditActionDelete
case glfw.KeyD:
if modifier == glfw.ModControl {
return EditActionDelete
}
case glfw.KeyK:
if modifier == glfw.ModControl {
return EditActionCutUntilLineEnd
}
case glfw.KeyY:
if modifier == glfw.ModControl {
return EditActionYank
}
case glfw.KeyEnter:
return EditActionEnter
case glfw.KeyC:
if (!isMac && modifier == glfw.ModControl) || (isMac && modifier == glfw.ModSuper) {
return EditActionCopy
}
case glfw.KeyX:
if (!isMac && modifier == glfw.ModControl) || (isMac && modifier == glfw.ModSuper) {
return EditActionCut
}
case glfw.KeyV:
if (!isMac && modifier == glfw.ModControl) || (isMac && modifier == glfw.ModSuper) {
return EditActionPaste
}
}
return EditActionNone
}