mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
Compare commits
No commits in common. "ec9b0882ab670437c5a85f35fd442bb347ee6f4c" and "5df1462dc9a17a6ecbc128a67ca4d2b76e633a2d" have entirely different histories.
ec9b0882ab
...
5df1462dc9
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -167,10 +167,9 @@ jobs:
|
||||
env GOARCH=386 EBITENGINE_DIRECTX=version=12 go test -shuffle=on -v ./...
|
||||
|
||||
- name: go test (Wasm)
|
||||
if: ${{ runner.os != 'macOS' && runner.os != 'Windows' }}
|
||||
if: runner.os != 'macOS'
|
||||
run: |
|
||||
# Wasm tests don't work on macOS with the headless mode, and the headless mode doesn't work in GitHub Actions (#2972).
|
||||
# Wasm tests don't work on Windows well due to mysterious timeouts (#2982).
|
||||
env GOOS=js GOARCH=wasm cleanenv -remove-prefix GITHUB_ -remove-prefix JAVA_ -remove-prefix PSModulePath -remove-prefix STATS_ -remove-prefix RUNNER_ -- go test -shuffle=on -v ./...
|
||||
|
||||
- name: Install ebitenmobile
|
||||
|
@ -106,7 +106,7 @@ func (f *Field) HandleInput(x, y int) (handled bool, err error) {
|
||||
f.ch, f.end = Start(x, y)
|
||||
// Start returns nil for non-supported envrionments.
|
||||
if f.ch == nil {
|
||||
return false, nil
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ package textinput
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
@ -80,10 +79,7 @@ func (t *textInput) init() {
|
||||
e.Call("preventDefault")
|
||||
}
|
||||
if e.Get("code").String() == "Enter" || e.Get("key").String() == "Enter" {
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true.
|
||||
e.Call("preventDefault")
|
||||
ui.Get().UpdateInputFromEvent(e)
|
||||
t.trySend(true)
|
||||
// Ignore Enter key to avoid ebiten.IsKeyPressed(ebiten.KeyEnter) unexpectedly becomes true, especially for iOS Safari.
|
||||
return nil
|
||||
}
|
||||
if !e.Get("isComposing").Bool() {
|
||||
@ -100,11 +96,6 @@ func (t *textInput) init() {
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "input", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
e := args[0]
|
||||
// On iOS Safari, `isComposing` can be undefined.
|
||||
if e.Get("isComposing").IsUndefined() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
if e.Get("isComposing").Bool() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
@ -118,12 +109,8 @@ func (t *textInput) init() {
|
||||
t.trySend(true)
|
||||
return nil
|
||||
}
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion with a virtual keyboard.
|
||||
if isVirtualKeyboard() {
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}
|
||||
t.trySend(true)
|
||||
// Though `isComposing` is false, send the text as being not committed for text completion on mobile browsers.
|
||||
t.trySend(false)
|
||||
return nil
|
||||
}))
|
||||
t.textareaElement.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) any {
|
||||
@ -185,13 +172,7 @@ func (t *textInput) Start(x, y int) (chan State, func()) {
|
||||
s := newSession()
|
||||
t.session = s
|
||||
}
|
||||
return t.session.ch, func() {
|
||||
if t.session != nil {
|
||||
t.session.end()
|
||||
// Reset the session explictly, or a new session cannot be created above.
|
||||
t.session = nil
|
||||
}
|
||||
}
|
||||
return t.session.ch, t.session.end
|
||||
}
|
||||
|
||||
if t.session != nil {
|
||||
@ -212,10 +193,6 @@ func (t *textInput) trySend(committed bool) {
|
||||
}
|
||||
|
||||
textareaValue := t.textareaElement.Get("value").String()
|
||||
if textareaValue == "" {
|
||||
return
|
||||
}
|
||||
|
||||
start := t.textareaElement.Get("selectionStart").Int()
|
||||
end := t.textareaElement.Get("selectionEnd").Int()
|
||||
startInBytes := convertUTF16CountToByteCount(textareaValue, start)
|
||||
@ -236,15 +213,3 @@ func (t *textInput) trySend(committed bool) {
|
||||
t.textareaElement.Set("value", "")
|
||||
}
|
||||
}
|
||||
|
||||
func isVirtualKeyboard() bool {
|
||||
// Detect a virtual keyboard by the user agent.
|
||||
// Note that this is not a correct way to detect a virtual keyboard.
|
||||
// In the future, we should use the `navigator.virtualKeyboard` API.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/virtualKeyboard
|
||||
ua := js.Global().Get("navigator").Get("userAgent").String()
|
||||
if strings.Contains(ua, "Android") || strings.Contains(ua, "iPhone") || strings.Contains(ua, "iPad") || strings.Contains(ua, "iPod") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user