internal/ui: refactoring: rename uiKeyToJSKey to uiKeyToJSCode

This commit is contained in:
Hajime Hoshi 2024-02-03 15:11:28 +09:00
parent d10636d235
commit 7dd22fdc61
3 changed files with 8 additions and 8 deletions

View File

@ -593,7 +593,7 @@ import (
"syscall/js"
)
var uiKeyToJSKey = map[Key]js.Value{
var uiKeyToJSCode = map[Key]js.Value{
{{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
{{end}}
}

View File

@ -38,11 +38,11 @@ type touchInClient struct {
y float64
}
func jsKeyToID(key js.Value) Key {
func jsCodeToID(code js.Value) Key {
// js.Value cannot be used as a map key.
// As the number of keys is around 100, just a dumb loop should work.
for uiKey, jsKey := range uiKeyToJSKey {
if jsKey.Equal(key) {
for uiKey, jsCode := range uiKeyToJSCode {
if jsCode.Equal(code) {
return uiKey
}
}
@ -58,7 +58,7 @@ var codeToMouseButton = map[int]MouseButton{
}
func (u *UserInterface) keyDown(code js.Value) {
id := jsKeyToID(code)
id := jsCodeToID(code)
if id < 0 {
return
}
@ -66,7 +66,7 @@ func (u *UserInterface) keyDown(code js.Value) {
}
func (u *UserInterface) keyUp(code js.Value) {
id := jsKeyToID(code)
id := jsCodeToID(code)
if id < 0 {
return
}
@ -216,7 +216,7 @@ func (u *UserInterface) KeyName(key Key) string {
u.keyboardLayoutMap = <-jsKeyboardGetLayoutMapCh
}
n := u.keyboardLayoutMap.Call("get", uiKeyToJSKey[key])
n := u.keyboardLayoutMap.Call("get", uiKeyToJSCode[key])
if n.IsUndefined() {
return ""
}

View File

@ -20,7 +20,7 @@ import (
"syscall/js"
)
var uiKeyToJSKey = map[Key]js.Value{
var uiKeyToJSCode = map[Key]js.Value{
KeyA: js.ValueOf("KeyA"),
KeyAltLeft: js.ValueOf("AltLeft"),
KeyAltRight: js.ValueOf("AltRight"),