forked from c-bata/go-prompt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkey_bind_func.go
48 lines (40 loc) · 1.16 KB
/
key_bind_func.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
package prompt
import (
istrings "github.com/elk-language/go-prompt/strings"
)
// GoLineEnd Go to the End of the line
func GoLineEnd(p *Prompt) bool {
x := []rune(p.buffer.Document().TextAfterCursor())
return p.CursorRightRunes(istrings.RuneNumber(len(x)))
}
// GoLineBeginning Go to the beginning of the line
func GoLineBeginning(p *Prompt) bool {
x := []rune(p.buffer.Document().TextBeforeCursor())
return p.CursorLeftRunes(istrings.RuneNumber(len(x)))
}
// DeleteChar Delete character under the cursor
func DeleteChar(p *Prompt) bool {
p.buffer.Delete(1, p.renderer.col, p.renderer.row)
return true
}
// DeleteBeforeChar Go to Backspace
func DeleteBeforeChar(p *Prompt) bool {
p.buffer.DeleteBeforeCursor(1, p.renderer.col, p.renderer.row)
return true
}
// GoRightChar Forward one character
func GoRightChar(p *Prompt) bool {
return p.CursorRight(1)
}
// GoLeftChar Backward one character
func GoLeftChar(p *Prompt) bool {
return p.CursorLeft(1)
}
func DeleteWordBeforeCursor(p *Prompt) bool {
p.buffer.DeleteBeforeCursorRunes(
istrings.RuneCountInString(p.buffer.Document().GetWordBeforeCursorWithSpace()),
p.renderer.col,
p.renderer.row,
)
return true
}