Fix edit bar cursor

This commit is contained in:
Zachary Yedidia
2016-04-08 09:30:36 -04:00
parent 41982fe8e1
commit 5330e0e5a5
2 changed files with 7 additions and 2 deletions

View File

@@ -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++
}
}

View File

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