-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.go
51 lines (46 loc) · 1.04 KB
/
change.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
package main
// Insert inserts content to the file.
func (file *File) Insert(content string) {
file.content = file.content[:file.location] + content + file.content[file.location:]
file.location += len(content)
file.changed = true
file.Archive()
}
// Backspace deletes rune on the left.
func (file *File) Backspace() {
if file.AtFileStart() {
return
}
file.MoveLeft()
file.Delete()
}
// Delete removes current rune.
func (file *File) Delete() {
if file.AtFileEnd() {
return
}
_, size := file.current()
from := file.location
to := from + size
file.Remove(from, to)
}
// DeleteLine removes current line.
func (file *File) DeleteLine() {
location := file.location
file.MoveLineStart()
from := file.location
file.MoveLineEnd()
file.MoveRight()
to := file.location
file.location = location
file.Remove(from, to)
}
// Remove deletes content from the file.
func (file *File) Remove(from, to int) {
file.content = file.content[:from] + file.content[to:]
if file.location > from {
file.location = from
}
file.changed = true
file.Archive()
}