-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathundo.go
More file actions
47 lines (37 loc) · 1.01 KB
/
undo.go
File metadata and controls
47 lines (37 loc) · 1.01 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
package readline
import (
"strings"
)
func (rl *Instance) undoAppendHistory() {
if rl.viUndoSkipAppend {
rl.viUndoSkipAppend = false
return
}
rl.viUndoHistory = append(rl.viUndoHistory, rl.line.Duplicate())
}
func (rl *Instance) undoLastStr() string {
var undo *UnicodeT
for {
if len(rl.viUndoHistory) == 0 {
return ""
}
undo = rl.viUndoHistory[len(rl.viUndoHistory)-1]
rl.viUndoHistory = rl.viUndoHistory[:len(rl.viUndoHistory)-1]
if undo.String() != rl.line.String() {
break
}
}
output := rl.clearHelpersStr()
output += moveCursorBackwardsStr(rl.line.CellPos())
output += strings.Repeat(" ", rl.line.CellLen())
output += moveCursorBackwardsStr(rl.line.CellLen())
output += moveCursorForwardsStr(undo.CellPos())
rl.line = undo.Duplicate()
output += rl.echoStr()
// TODO: check me
if rl.modeViMode != vimInsert && rl.line.RuneLen() > 0 && rl.line.RunePos() == rl.line.RuneLen() {
rl.line.SetRunePos(rl.line.RuneLen() - 1)
output += moveCursorBackwardsStr(1)
}
return output
}