ui: Bug fix: call preventDefault for arrow keys

Fixes #450
This commit is contained in:
Hajime Hoshi 2017-11-10 00:32:47 +09:00
parent f789c285ad
commit 0c0cd7e9d6

View File

@ -244,14 +244,26 @@ func initialize() error {
// Keyboard // Keyboard
canvas.Call("addEventListener", "keydown", func(e *js.Object) { canvas.Call("addEventListener", "keydown", func(e *js.Object) {
if e.Get("code") == js.Undefined { c := e.Get("code")
// Assume that UA is Safari. if c == js.Undefined {
// TODO: Now this is used for Edge, not Safari. Rename functions.
code := e.Get("keyCode").Int() code := e.Get("keyCode").Int()
currentInput.keyDownSafari(code) if keyCodeToKeySafari[code] == KeyUp ||
keyCodeToKeySafari[code] == KeyDown ||
keyCodeToKeySafari[code] == KeyLeft ||
keyCodeToKeySafari[code] == KeyRight {
currentInput.keyDownSafari(code)
}
return return
} }
code := e.Get("code").String() cs := c.String()
currentInput.keyDown(code) if cs == keyToCodes[KeyUp][0] ||
cs == keyToCodes[KeyDown][0] ||
cs == keyToCodes[KeyLeft][0] ||
cs == keyToCodes[KeyRight][0] {
e.Call("preventDefault")
}
currentInput.keyDown(cs)
}) })
canvas.Call("addEventListener", "keypress", func(e *js.Object) { canvas.Call("addEventListener", "keypress", func(e *js.Object) {
e.Call("preventDefault") e.Call("preventDefault")