-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtext_edit.go
More file actions
50 lines (46 loc) · 1.02 KB
/
Copy pathtext_edit.go
File metadata and controls
50 lines (46 loc) · 1.02 KB
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
package main
func (state AppState) typeKey(key string) AppState {
switch state.CurrentMode {
case selectCategory:
state.selectCategoryBuffer = state.selectCategoryBuffer.typeKey(key)
case search:
state.searchBuffer = state.searchBuffer.typeKey(key)
view := state.getSelectedView()
state.LogViews[state.selected] = view.scrollToSearch(state)
case editModifier:
newBuffer := state.modifiers[state.selectedMod].typeKey(key)
state.modifiers[state.selectedMod].buffer = newBuffer
}
return state
}
// buffer provides an abstraction over editing text
type buffer struct {
text string
}
func (t buffer) typeKey(key string) buffer {
key = convertKey(key)
switch key {
case "<BS>":
// Backspace
if len(t.text) > 0 {
t.text = t.text[:len(t.text)-1]
}
default:
t.text = t.text + key
}
return t
}
func convertKey(key string) string {
switch key {
case "<space>":
return " "
case "C-8":
return "<BS>"
default:
// Just ignore weird control sequences
if len(key) > 1 {
return ""
}
return key
}
}