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:]) +}