mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
exp/textinput, examples/textinput: bug fix: handle input states correctly on Android Chrome
Updates #2898
This commit is contained in:
parent
0adc1ad681
commit
5c7bfd3ed7
@ -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
|
||||
|
@ -91,7 +91,19 @@ func (t *textInput) init() {
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "input", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
e := args[0]
|
||||
t.trySend(!e.Get("isComposing").Bool())
|
||||
if e.Get("isComposing").Bool() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
if e.Get("inputType").String() == "insertLineBreak" {
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}))
|
||||
// TODO: What about other events like wheel?
|
||||
|
Loading…
Reference in New Issue
Block a user