Skip to content

Commit

Permalink
io,widget: [android] improve focus
Browse files Browse the repository at this point in the history
This patch is intended to fix two issues related to focus and
software-keyboard.

The focus is now reseted if it's lost due to external event,
such as clicking on non-Gio window/activity/fragment.

The software-keyboard will now re-open when clicked, except
if it's ReadOnly.

Fixes: https://todo.sr.ht/~eliasnaur/gio/591

Signed-off-by: inkeliz <inkeliz@inkeliz.com>
  • Loading branch information
inkeliz committed Jun 8, 2024
1 parent e6da07a commit 6433dc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions io/input/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,14 @@ func (q *Router) changeState(e event.Event, state inputState, evts []taggedEvent
e.event = de
}
}
for i := range evts {
e := &evts[i]
if fe, ok := e.event.(key.FocusEvent); ok {
if !fe.Focus {
state.keyState.focus = nil
}
}
}
// Initialize the first change to contain the current state
// and events that are bound for the current frame.
if len(q.changes) == 0 {
Expand Down
5 changes: 4 additions & 1 deletion widget/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ func (e *Editor) processPointerEvent(gtx layout.Context, ev event.Event) (Editor
Y: int(math.Round(float64(evt.Position.Y))),
})
gtx.Execute(key.FocusCmd{Tag: e})
if !e.ReadOnly {
gtx.Execute(key.SoftKeyboardCmd{Show: true})
}
if e.scroller.State() != gesture.StateFlinging {
e.scrollCaret = true
}
Expand Down Expand Up @@ -395,7 +398,7 @@ func (e *Editor) processKey(gtx layout.Context) (EditorEvent, bool) {
case key.FocusEvent:
// Reset IME state.
e.ime.imeState = imeState{}
if ke.Focus {
if ke.Focus && !e.ReadOnly {
gtx.Execute(key.SoftKeyboardCmd{Show: true})
}
case key.Event:
Expand Down

0 comments on commit 6433dc3

Please sign in to comment.