exp/textinput, examples/textinput: bug fix: handle input states correctly on Android Chrome

Updates #2898
This commit is contained in:
Hajime Hoshi
2024-02-03 22:16:16 +09:00
parent 0adc1ad681
commit 5c7bfd3ed7
2 changed files with 28 additions and 1 deletions

View File

@@ -138,6 +138,21 @@ func (t *TextField) Blur() {
func (t *TextField) Update() {
if !t.focused {
// If the text field still has a session, read the last state and process it just in case.
if t.ch != nil {
select {
case state, ok := <-t.ch:
if ok && state.Committed {
t.text = t.text[:t.selectionStart] + state.Text + t.text[t.selectionEnd:]
t.selectionStart += len(state.Text)
t.selectionEnd = t.selectionStart
t.state = textinput.State{}
}
t.state = state
default:
break
}
}
if t.end != nil {
t.end()
t.ch = nil