Work
This commit is contained in:
21
field.go
21
field.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user