forked from steverusso/mdedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
86 lines (76 loc) · 1.46 KB
/
activity.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
package mdedit
import "bytes"
type action struct {
cmd command
change change
}
type command struct {
modChar byte
opCount int
opChar byte
cmdCount int
cmdChar byte
motionCount int
motionChar1 byte
motionChar2 byte
}
func (c *command) process(char byte) {
if char == '0' && c.motionCount == 0 {
c.motionChar1 = '0'
} else if char >= '0' && char <= '9' {
c.motionCount = (c.motionCount * 10) + int(char-'0')
}
switch char {
case 'g', 'z':
c.modChar = char
case '.', 'u', 'I', 'S', 'o', 'O', 'C', 'A', 'x':
c.cmdChar = char
case 'c', 'd', 'y':
if c.opChar == char {
c.motionChar1 = char
} else {
c.opChar = char
}
case 'i', 'a':
if c.opChar == 0 {
c.cmdChar = char
} else {
c.motionChar1 = char
}
case 'w', 'e', 'b':
if c.motionChar1 == 0 {
c.motionChar1 = char
} else {
c.motionChar2 = char
}
case ' ':
if c.modChar != 0 {
c.cmdChar = char
break
}
fallthrough
case 'h', 'l', '$':
c.motionChar1 = char
case 'j', 'k', 'H', 'L':
c.motionChar1 = char
}
}
var motionChars = []byte("jkhl LHweWEb0$")
func (c *command) hasMotion() bool {
return bytes.IndexByte(motionChars, c.motionChar1) != -1 ||
(c.motionChar2 != 0 && (c.motionChar1 == 'i' || c.motionChar1 == 'a'))
}
type change struct {
typ changeType
from position
content content
}
type changeType byte
const (
changeAddition changeType = iota
changeDeletion
)
type content struct {
simple []byte
lines []line
}