mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
exp/textinput: bug fix: keyboards didn't show immediately after touching
Updates #2898
This commit is contained in:
parent
7eee3929de
commit
0160d40bfb
@ -15,7 +15,6 @@
|
|||||||
package textinput
|
package textinput
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||||
@ -133,7 +132,8 @@ let handler = (e) => {
|
|||||||
|
|
||||||
let body = window.document.body;
|
let body = window.document.body;
|
||||||
body.addEventListener("click", handler);
|
body.addEventListener("click", handler);
|
||||||
body.addEventListener("touchstart", handler);`)
|
body.addEventListener("touchend", handler);
|
||||||
|
body.addEventListener("keyup", handler);`)
|
||||||
|
|
||||||
// TODO: What about other events like wheel?
|
// TODO: What about other events like wheel?
|
||||||
}
|
}
|
||||||
@ -143,29 +143,15 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if js.Global().Get("_ebitengine_textinput_ready").Truthy() {
|
|
||||||
s := newSession()
|
|
||||||
t.session = s
|
|
||||||
js.Global().Get("window").Set("_ebitengine_textinput_ready", js.Undefined())
|
|
||||||
return s.ch, s.end
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.session != nil {
|
if t.session != nil {
|
||||||
t.session.end()
|
t.session.end()
|
||||||
t.session = nil
|
t.session = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a textarea is focused, create a session immediately.
|
if js.Global().Get("_ebitengine_textinput_ready").Truthy() {
|
||||||
// A virtual keyboard should already be shown on mobile browsers.
|
|
||||||
if document.Get("activeElement").Equal(t.textareaElement) {
|
|
||||||
t.textareaElement.Set("value", "")
|
|
||||||
t.textareaElement.Call("focus")
|
|
||||||
style := t.textareaElement.Get("style")
|
|
||||||
style.Set("left", fmt.Sprintf("%dpx", x))
|
|
||||||
style.Set("top", fmt.Sprintf("%dpx", y))
|
|
||||||
|
|
||||||
s := newSession()
|
s := newSession()
|
||||||
t.session = s
|
t.session = s
|
||||||
|
js.Global().Get("window").Set("_ebitengine_textinput_ready", js.Undefined())
|
||||||
return s.ch, s.end
|
return s.ch, s.end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user