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 {
|
} else if ac.Key == prompt.Enter || ac.Key == prompt.ControlJ {
|
||||||
buffer.InsertText("\n", false, true)
|
buffer.InsertText("\n", false, true)
|
||||||
} else if ac.Key == prompt.Left {
|
} else if ac.Key == prompt.Left {
|
||||||
buffer.CursorLeft(1)
|
l := buffer.CursorLeft(1)
|
||||||
|
if l == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
out.CursorDown(1)
|
out.CursorDown(1)
|
||||||
out.CursorBackward(1)
|
out.CursorBackward(1)
|
||||||
out.EraseDown()
|
out.EraseDown()
|
||||||
out.CursorUp(1)
|
out.CursorUp(1)
|
||||||
} else if ac.Key == prompt.Right {
|
} else if ac.Key == prompt.Right {
|
||||||
buffer.CursorRight(1)
|
l := buffer.CursorRight(1)
|
||||||
|
if l == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
out.CursorDown(1)
|
out.CursorDown(1)
|
||||||
out.EraseDown()
|
out.EraseDown()
|
||||||
out.CursorForward(1)
|
out.CursorForward(1)
|
||||||
|
@ -99,13 +99,17 @@ func (b *Buffer) setDocument(d *Document) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CursorLeft move to left on the current line.
|
// CursorLeft move to left on the current line.
|
||||||
func (b *Buffer) CursorLeft(count int) {
|
func (b *Buffer) CursorLeft(count int) int {
|
||||||
b.CursorPosition += b.Document().GetCursorLeftPosition(count)
|
l := b.Document().GetCursorLeftPosition(count)
|
||||||
|
b.CursorPosition += l
|
||||||
|
return -l
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorRight move to right on the current line.
|
// CursorRight move to right on the current line.
|
||||||
func (b *Buffer) CursorRight(count int) {
|
func (b *Buffer) CursorRight(count int) int {
|
||||||
b.CursorPosition += b.Document().GetCursorRightPosition(count)
|
l := b.Document().GetCursorRightPosition(count)
|
||||||
|
b.CursorPosition += l
|
||||||
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorUp move cursor to the previous line.
|
// CursorUp move cursor to the previous line.
|
||||||
|
Loading…
Reference in New Issue
Block a user