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)
|
ui.ActivateControl(view, edit)
|
||||||
|
|
||||||
edit.OnKeyPress(func(key term.Key) bool {
|
edit.OnKeyPress(func(key term.Key, ch rune) bool {
|
||||||
if key == term.KeyCtrlM {
|
if key == term.KeyCtrlM {
|
||||||
v := edit.Title()
|
v := edit.Title()
|
||||||
logBox.AddItem(fmt.Sprintf("New PB value(KeyPress): %v", v))
|
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
|
// 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
|
// true. If handler returns false it means that the default handler will
|
||||||
// process the key
|
// 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
|
e.onKeyPress = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ type EditField struct {
|
||||||
showStars bool
|
showStars bool
|
||||||
|
|
||||||
onChange func(Event)
|
onChange func(Event)
|
||||||
onKeyPress func(term.Key) bool
|
onKeyPress func(term.Key, rune) bool
|
||||||
|
|
||||||
lastEvent time.Time
|
lastEvent time.Time
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ func (e *EditField) ProcessEvent(event Event) bool {
|
||||||
|
|
||||||
if event.Type == EventKey && event.Key != term.KeyTab {
|
if event.Type == EventKey && event.Key != term.KeyTab {
|
||||||
if e.onKeyPress != nil {
|
if e.onKeyPress != nil {
|
||||||
res := e.onKeyPress(event.Key)
|
res := e.onKeyPress(event.Key, event.Ch)
|
||||||
if res {
|
if res {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ type EditField struct {
|
||||||
showStars bool
|
showStars bool
|
||||||
|
|
||||||
onChange func(Event)
|
onChange func(Event)
|
||||||
onKeyPress func(term.Key) bool
|
onKeyPress func(term.Key, rune) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEditField creates a new EditField control
|
// 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 event.Type == EventKey && event.Key != term.KeyTab {
|
||||||
if e.onKeyPress != nil {
|
if e.onKeyPress != nil {
|
||||||
res := e.onKeyPress(event.Key)
|
res := e.onKeyPress(event.Key, event.Ch)
|
||||||
if res {
|
if res {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue