-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay_logic.go
53 lines (47 loc) · 1.26 KB
/
display_logic.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
package main
func oneCharOperation(c *Display, f func()) {
oldH := c.getCurrentEl().getOnScreenLineEndingY()
oldCursorY := c.getCurrentEl().getRelativeCursorY()
f()
newH := c.getCurrentEl().getOnScreenLineEndingY()
newCursorY := c.getCurrentEl().getRelativeCursorY()
if oldCursorY != newCursorY {
c.resyncNewCursorY()
} else {
if oldH != newH {
c.resyncBelow(c.currentElement)
} else {
c.getCurrentEl().resync()
}
}
}
func (c *Display) insert(char rune) {
oneCharOperation(c, func() {
c.getCurrentEl().data = insertInSlice(c.getCurrentEl().data, char, c.getCurrentEl().pos)
c.getCurrentEl().pos++
})
}
func (c *Display) remove() {
if c.getCurrentEl().pos == 0 {
if !c.hasPrevEl() {
return
}
// Remove current line
p := c.currentElement.Prev()
p.Value.(*Line).pos = len(p.Value.(*Line).data)
p.Value.(*Line).data = append(p.Value.(*Line).data, c.getCurrentEl().data...)
c.data.Remove(c.currentElement)
c.currentElement = p
c.recalcBelow(c.currentElement)
// Fix Y!
if c.getCurrentEl().getOnScreenCursorY() < 0 {
c.offsetY--
}
c.resyncBelow(c.data.Front())
} else {
oneCharOperation(c, func() {
c.getCurrentEl().pos--
c.getCurrentEl().data = removeFromSlice(c.getCurrentEl().data, c.getCurrentEl().pos)
})
}
}