From 68147da8e92e5fb190cf91d3417a4ee8007cadf3 Mon Sep 17 00:00:00 2001 From: c-bata Date: Sun, 9 Jul 2017 22:55:59 +0900 Subject: [PATCH] Improve left and right moving --- main.go | 10 ++++++++-- prompt/buffer.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index fe125df..8778dc0 100644 --- a/main.go +++ b/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) diff --git a/prompt/buffer.go b/prompt/buffer.go index 6c57c9a..139f54e 100644 --- a/prompt/buffer.go +++ b/prompt/buffer.go @@ -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.