Improve left and right moving

This commit is contained in:
c-bata 2017-07-09 22:55:59 +09:00
parent 733829a997
commit 68147da8e9
2 changed files with 16 additions and 6 deletions

10
main.go
View File

@ -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)

View File

@ -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.