edit: pass event.Ch to OnKeyPress callback
It seems beneficial the callback to also know the event.Ch so we can implement more "sophisticated" field filling validation strategies.
This commit is contained in:
parent
8d3cd97d8e
commit
efa32413a4
|
@ -91,7 +91,7 @@ func createView() {
|
|||
|
||||
ui.ActivateControl(view, edit)
|
||||
|
||||
edit.OnKeyPress(func(key term.Key) bool {
|
||||
edit.OnKeyPress(func(key term.Key, ch rune) bool {
|
||||
if key == term.KeyCtrlM {
|
||||
v := edit.Title()
|
||||
logBox.AddItem(fmt.Sprintf("New PB value(KeyPress): %v", v))
|
||||
|
|
2
edit.go
2
edit.go
|
@ -15,7 +15,7 @@ func (e *EditField) OnChange(fn func(Event)) {
|
|||
// the controls is active. If a handler processes the key it should return
|
||||
// true. If handler returns false it means that the default handler will
|
||||
// process the key
|
||||
func (e *EditField) OnKeyPress(fn func(term.Key) bool) {
|
||||
func (e *EditField) OnKeyPress(fn func(term.Key, rune) bool) {
|
||||
e.onKeyPress = fn
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ type EditField struct {
|
|||
showStars bool
|
||||
|
||||
onChange func(Event)
|
||||
onKeyPress func(term.Key) bool
|
||||
onKeyPress func(term.Key, rune) bool
|
||||
|
||||
lastEvent time.Time
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (e *EditField) ProcessEvent(event Event) bool {
|
|||
|
||||
if event.Type == EventKey && event.Key != term.KeyTab {
|
||||
if e.onKeyPress != nil {
|
||||
res := e.onKeyPress(event.Key)
|
||||
res := e.onKeyPress(event.Key, event.Ch)
|
||||
if res {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ type EditField struct {
|
|||
showStars bool
|
||||
|
||||
onChange func(Event)
|
||||
onKeyPress func(term.Key) bool
|
||||
onKeyPress func(term.Key, rune) bool
|
||||
}
|
||||
|
||||
// NewEditField creates a new EditField control
|
||||
|
@ -84,7 +84,7 @@ func (e *EditField) ProcessEvent(event Event) bool {
|
|||
|
||||
if event.Type == EventKey && event.Key != term.KeyTab {
|
||||
if e.onKeyPress != nil {
|
||||
res := e.onKeyPress(event.Key)
|
||||
res := e.onKeyPress(event.Key, event.Ch)
|
||||
if res {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue