io/router/key: add explicit tag to FocusOp; make last SoftKeyboardOp apply

The target of FocusOp is too subtle; be explicit instead and remove
any doubt.

Multiple SoftKeyboardOp in a single frame is rare, but if they do occur,
they should behave as if they were from separate frames: the last one
applies.

As a side-effect the key event router can be much simplified.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-01-22 16:04:10 +01:00
parent 95953b2ae0
commit e70a16c345
5 changed files with 41 additions and 106 deletions
+7 -8
View File
@@ -26,15 +26,17 @@ type InputOp struct {
}
// SoftKeyboardOp shows or hide the on-screen keyboard, if available.
// It replaces any previous SoftKeyboardOp.
type SoftKeyboardOp struct {
Show bool
}
// FocusOp sets or clears the keyboard focus.
// FocusOp sets or clears the keyboard focus. It replaces any previous
// FocusOp in the same frame.
type FocusOp struct {
// Focus, if set, moves the focus to the current InputOp. If Focus
// is false, the focus is cleared.
Focus bool
// Tag is the new focus. The focus is cleared if Tag is nil, or if Tag
// has no InputOp in the same frame.
Tag event.Tag
}
// A FocusEvent is generated when a handler gains or loses
@@ -132,11 +134,8 @@ func (h SoftKeyboardOp) Add(o *op.Ops) {
}
func (h FocusOp) Add(o *op.Ops) {
data := o.Write(opconst.TypeKeyFocusLen)
data := o.Write1(opconst.TypeKeyFocusLen, h.Tag)
data[0] = byte(opconst.TypeKeyFocus)
if h.Focus {
data[1] = 1
}
}
func (EditEvent) ImplementsEvent() {}