This commit is contained in:
2025-07-09 16:14:11 -05:00
parent 4763d1be26
commit 2e2aa50b82
13 changed files with 763 additions and 124 deletions

View File

@@ -41,9 +41,10 @@ type Field struct {
x, y int
w, h int
filter func(*tcell.EventKey) bool
filter func(*tcell.EventKey) bool
onChange func(prev, curr string)
keyMap KeyMap
}
var _ Widget = (*Field)(nil)
@@ -62,6 +63,13 @@ func (w *Field) Init(id string, style tcell.Style) {
return h.IsBS(*ev) ||
h.KeyIsDisplayable(*ev)
}
w.keyMap = NewKeyMap(map[tcell.Key]func() bool{
tcell.KeyLeft: w.handleLeft,
tcell.KeyRight: w.handleRight,
tcell.KeyHome: w.handleHome,
tcell.KeyEnd: w.handleEnd,
tcell.KeyCtrlU: w.clearValueBeforeCursor,
})
}
func (w *Field) Id() string { return w.id }
@@ -70,17 +78,10 @@ func (w *Field) HandleKey(ev *tcell.EventKey) bool {
if !w.active {
return false
}
if h.IsBS(*ev) {
return w.handleBackspace()
}
if h.HandleKeys(*ev, map[tcell.Key]func() bool{
tcell.KeyLeft: w.handleLeft,
tcell.KeyRight: w.handleRight,
tcell.KeyHome: w.handleHome,
tcell.KeyEnd: w.handleEnd,
tcell.KeyCtrlU: w.clearValueBeforeCursor,
}) {
if ok := w.keyMap.Handle(ev); ok {
return true
}
if w.filter != nil && !w.filter(ev) {