From 5330e0e5a52b4161597107e215b54ae9c3853633 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Fri, 8 Apr 2016 09:30:36 -0400 Subject: [PATCH] Fix edit bar cursor --- src/messenger.go | 4 ++-- src/util.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/messenger.go b/src/messenger.go index e7984bf3..aeafea0d 100644 --- a/src/messenger.go +++ b/src/messenger.go @@ -153,14 +153,14 @@ func (m *Messenger) HandleEvent(event tcell.Event) { } case tcell.KeyBackspace2: if m.cursorx > 0 { - m.response = string([]rune(m.response)[:Count(m.response)-1]) + m.response = string([]rune(m.response)[:m.cursorx-1]) + string(m.response[m.cursorx:]) } m.cursorx-- case tcell.KeySpace: m.response += " " m.cursorx++ case tcell.KeyRune: - m.response += string(e.Rune()) + m.response = Insert(m.response, m.cursorx, string(e.Rune())) m.cursorx++ } } diff --git a/src/util.go b/src/util.go index 2ad55387..069aff6f 100644 --- a/src/util.go +++ b/src/util.go @@ -70,3 +70,8 @@ func Contains(list []string, a string) bool { } return false } + +// Insert makes a simple insert into a string at the given position +func Insert(str string, pos int, value string) string { + return string([]rune(str)[:pos]) + value + string([]rune(str)[pos:]) +}