Improve left and right moving
This commit is contained in:
parent
733829a997
commit
68147da8e9
10
main.go
10
main.go
|
@ -43,13 +43,19 @@ func main() {
|
|||
} else if ac.Key == prompt.Enter || ac.Key == prompt.ControlJ {
|
||||
buffer.InsertText("\n", false, true)
|
||||
} else if ac.Key == prompt.Left {
|
||||
buffer.CursorLeft(1)
|
||||
l := buffer.CursorLeft(1)
|
||||
if l == 0 {
|
||||
continue
|
||||
}
|
||||
out.CursorDown(1)
|
||||
out.CursorBackward(1)
|
||||
out.EraseDown()
|
||||
out.CursorUp(1)
|
||||
} else if ac.Key == prompt.Right {
|
||||
buffer.CursorRight(1)
|
||||
l := buffer.CursorRight(1)
|
||||
if l == 0 {
|
||||
continue
|
||||
}
|
||||
out.CursorDown(1)
|
||||
out.EraseDown()
|
||||
out.CursorForward(1)
|
||||
|
|
|
@ -99,13 +99,17 @@ func (b *Buffer) setDocument(d *Document) {
|
|||
}
|
||||
|
||||
// CursorLeft move to left on the current line.
|
||||
func (b *Buffer) CursorLeft(count int) {
|
||||
b.CursorPosition += b.Document().GetCursorLeftPosition(count)
|
||||
func (b *Buffer) CursorLeft(count int) int {
|
||||
l := b.Document().GetCursorLeftPosition(count)
|
||||
b.CursorPosition += l
|
||||
return -l
|
||||
}
|
||||
|
||||
// CursorRight move to right on the current line.
|
||||
func (b *Buffer) CursorRight(count int) {
|
||||
b.CursorPosition += b.Document().GetCursorRightPosition(count)
|
||||
func (b *Buffer) CursorRight(count int) int {
|
||||
l := b.Document().GetCursorRightPosition(count)
|
||||
b.CursorPosition += l
|
||||
return l
|
||||
}
|
||||
|
||||
// CursorUp move cursor to the previous line.
|
||||
|
|
Loading…
Reference in New Issue