-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_bind.go
135 lines (129 loc) · 2.8 KB
/
key_bind.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package chooser
type bufferKeyBindingCmd struct {
function func(*buffer)
key string
description string
}
type renderKeyBindingCmd struct {
function func(*render, bool)
key string
description string
}
type keyBindingCmd struct {
key string
description string
}
var bufferKeyBindingCmds = map[int]bufferKeyBindingCmd{
delete: {
function: func(b *buffer) {
b.deleteCharOnCursor()
},
key: "delete",
description: "Delete a character under cursor.",
},
controlD: {
function: func(b *buffer) {
b.deleteCharOnCursor()
},
key: "controlD",
description: "Delete a character under cursor.",
},
backspace: {
function: func(b *buffer) {
b.backwardDeleteChar()
},
key: "backspace",
description: "Delete a character before cursor.",
},
controlH: {
function: func(b *buffer) {
b.backwardDeleteChar()
},
key: "controlH",
description: "Delete a character before cursor.",
},
controlF: {
function: func(b *buffer) {
b.forwardChar()
},
key: "controlF",
description: "Move forward a character.",
},
controlB: {
function: func(b *buffer) {
b.backwardChar()
},
key: "controlB",
description: "Move backward a character.",
},
controlA: {
function: func(b *buffer) {
b.beginningOfLine()
},
key: "controlA",
description: "Go to the beginning of the line.",
},
controlE: {
function: func(b *buffer) {
b.endOfLine()
},
key: "controlE",
description: "Go to the end of the line.",
},
controlU: {
function: func(b *buffer) {
b.backwardKillLine()
},
key: "controlU",
description: "Kill characters from cursor current position to the beginning of the line.",
},
controlK: {
function: func(b *buffer) {
b.killLine()
},
key: "controlK",
description: "Kill characters from cursor current position to the end of the line.",
},
controlW: {
function: func(b *buffer) {
b.backwardKillWord()
},
key: "controlW",
description: "Delete before a word.",
},
}
var renderKeyBindingCmds = map[int]renderKeyBindingCmd{
controlN: {
function: func(r *render, _ bool) {
r.next()
},
key: "controlN",
description: "Move the cursor to the next line.",
},
controlP: {
function: func(r *render, _ bool) {
r.previous()
},
key: "controlP",
description: "Move the cursor to the previous line.",
},
tab: {
function: func(r *render, isMultiple bool) {
if isMultiple {
r.holdCompletion()
}
},
key: "tab",
description: "Store the line on the cursor.",
},
}
var keyBindingCmds = map[int]keyBindingCmd{
enter: {
key: "enter",
description: "Choose the line on the cursor. Or choose the stored lines.",
},
controlC: {
key: "controlC",
description: "Cancel.",
},
}