From 7dd22fdc61f5d198fd6995ea570ae93fa3bbeb65 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Feb 2024 15:11:28 +0900 Subject: [PATCH] internal/ui: refactoring: rename uiKeyToJSKey to uiKeyToJSCode --- genkeys.go | 2 +- internal/ui/input_js.go | 12 ++++++------ internal/ui/keys_js.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/genkeys.go b/genkeys.go index 94d1bbbe2..05ee9ebb5 100644 --- a/genkeys.go +++ b/genkeys.go @@ -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}} } diff --git a/internal/ui/input_js.go b/internal/ui/input_js.go index 8bc0620cc..1adcb5149 100644 --- a/internal/ui/input_js.go +++ b/internal/ui/input_js.go @@ -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 "" } diff --git a/internal/ui/keys_js.go b/internal/ui/keys_js.go index 6678a2c21..26c3ea73f 100644 --- a/internal/ui/keys_js.go +++ b/internal/ui/keys_js.go @@ -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"),