-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.go
65 lines (57 loc) · 1.18 KB
/
update.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
package readline
func (rl *Instance) insert(r []rune) {
for {
// I don't really understand why `0` is creeping in at the end of the
// array but it only happens with unicode characters.
if len(r) > 1 && r[len(r)-1] == 0 {
r = r[:len(r)-1]
continue
}
break
}
switch {
case len(rl.line) == 0:
rl.line = r
case rl.pos == 0:
rl.line = append(r, rl.line...)
case rl.pos < len(rl.line):
r := append(r, rl.line[rl.pos:]...)
rl.line = append(rl.line[:rl.pos], r...)
default:
rl.line = append(rl.line, r...)
}
rl.moveCursorByAdjust(len(r))
rl.echo()
if rl.modeViMode == vimInsert {
rl.updateHelpers()
}
}
func (rl *Instance) backspace() {
if len(rl.line) == 0 || rl.pos == 0 {
return
}
moveCursorBackwards(1)
rl.pos--
rl.delete()
}
func (rl *Instance) delete() {
switch {
case len(rl.line) == 0:
return
case rl.pos == 0:
rl.line = rl.line[1:]
rl.echo()
//moveCursorBackwards(1)
case rl.pos > len(rl.line):
rl.backspace()
case rl.pos == len(rl.line):
rl.line = rl.line[:rl.pos]
rl.echo()
//moveCursorBackwards(1)
default:
rl.line = append(rl.line[:rl.pos], rl.line[rl.pos+1:]...)
rl.echo()
//moveCursorBackwards(1)
}
rl.updateHelpers()
}