KeyMap Expansion

This commit is contained in:
2025-07-31 13:31:14 -05:00
parent 174fab2c6d
commit 9e88799391
7 changed files with 111 additions and 54 deletions

View File

@@ -63,7 +63,7 @@ func (w *Field) Init(id string, style tcell.Style) {
return h.IsBS(*ev) ||
h.KeyIsDisplayable(*ev)
}
w.keyMap = NewKeyMap(map[tcell.Key]func() bool{
w.keyMap = NewKeyMap(map[tcell.Key]func(ev *tcell.EventKey) bool{
tcell.KeyLeft: w.handleLeft,
tcell.KeyRight: w.handleRight,
tcell.KeyHome: w.handleHome,
@@ -79,7 +79,7 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
return false
}
if h.IsBS(*ev) {
return w.handleBackspace()
return w.handleBackspace(ev)
}
if ok := w.keyMap.Handle(ev); ok {
return true
@@ -153,7 +153,7 @@ func (w *Field) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Field) Focusable() bool { return true }
/* Non-Widget-Interface Functions */
func (w *Field) handleBackspace() bool {
func (w *Field) handleBackspace(ev *tcell.EventKey) bool {
st := w.cursor
if w.cursor > 0 {
w.cursor--
@@ -167,7 +167,7 @@ func (w *Field) handleBackspace() bool {
return false
}
func (w *Field) handleLeft() bool {
func (w *Field) handleLeft(ev *tcell.EventKey) bool {
if w.cursor > 0 {
w.cursor--
return true
@@ -175,7 +175,7 @@ func (w *Field) handleLeft() bool {
return false
}
func (w *Field) handleRight() bool {
func (w *Field) handleRight(ev *tcell.EventKey) bool {
if w.cursor < len(w.value) {
w.cursor++
return true
@@ -183,18 +183,18 @@ func (w *Field) handleRight() bool {
return false
}
func (w *Field) clearValueBeforeCursor() bool {
func (w *Field) clearValueBeforeCursor(ev *tcell.EventKey) bool {
w.SetValue(w.value[w.cursor:])
w.cursor = 0
return true
}
func (w *Field) handleHome() bool {
func (w *Field) handleHome(ev *tcell.EventKey) bool {
w.cursor = 0
return true
}
func (w *Field) handleEnd() bool {
func (w *Field) handleEnd(ev *tcell.EventKey) bool {
w.cursor = len(w.value)
return true
}