From 8f99fdf709aff17f08095aacfb22977899e2a709 Mon Sep 17 00:00:00 2001 From: Chyroc Date: Wed, 11 Apr 2018 20:14:57 +0800 Subject: [PATCH] fix https://github.com/c-bata/go-prompt/issues/63 --- key_bind_func.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 key_bind_func.go diff --git a/key_bind_func.go b/key_bind_func.go new file mode 100644 index 0000000..45ab49e --- /dev/null +++ b/key_bind_func.go @@ -0,0 +1,44 @@ +package prompt + +// CursorLineEnd Go to the End of the line +func GoLineEnd(buf *Buffer) { + x := []rune(buf.Document().TextAfterCursor()) + buf.CursorRight(len(x)) +} + +// GoLineBeginning Go to the beginning of the line +func GoLineBeginning(buf *Buffer) { + x := []rune(buf.Document().TextBeforeCursor()) + buf.CursorLeft(len(x)) +} + +// DeleteChar Delete character under the cursor +func DeleteChar(buf *Buffer) { + buf.Delete(1) +} + +// DeleteBeforeChar Go to Backspace +func DeleteBeforeChar(buf *Buffer) { + buf.DeleteBeforeCursor(1) +} + +// GoRightChar Forward one character +func GoRightChar(buf *Buffer) { + buf.CursorRight(1) +} + +// GoLeftChar Backward one character +func GoLeftChar(buf *Buffer) { + buf.CursorLeft(1) +} + +// GoRightWord Forward one word +func GoRightWord(buf *Buffer) { + // fmt.Printf("%#v\n", buf.Document().FindEndOfCurrentWordWithSpace()) + buf.CursorRight(buf.Document().FindEndOfCurrentWordWithSpace()) +} + +// GoLeftWord Backward one word +func GoLeftWord(buf *Buffer) { + buf.CursorLeft(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace()) +}