From 37ca48dc38415f8f1bd592ca07358ff21e591a66 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 10 Nov 2017 00:35:46 +0900 Subject: [PATCH] ui: Rename functions from Safari to Edge --- genkeys.go | 18 +++++++++--------- internal/ui/input_js.go | 24 ++++++++++++------------ internal/ui/keys_js.go | 2 +- internal/ui/ui_js.go | 15 +++++++-------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/genkeys.go b/genkeys.go index a68a2b671..e5f6c9d9d 100644 --- a/genkeys.go +++ b/genkeys.go @@ -32,8 +32,8 @@ import ( ) var ( - nameToCodes map[string][]string - keyCodeToNameSafari map[int]string + nameToCodes map[string][]string + keyCodeToNameEdge map[int]string ) func init() { @@ -84,7 +84,7 @@ func init() { } func init() { - keyCodeToNameSafari = map[int]string{ + keyCodeToNameEdge = map[int]string{ 0xbc: "Comma", 0xbe: "Period", 0x12: "Alt", @@ -118,15 +118,15 @@ func init() { } // ASCII: 0 - 9 for c := '0'; c <= '9'; c++ { - keyCodeToNameSafari[int(c)] = string(c) + keyCodeToNameEdge[int(c)] = string(c) } // ASCII: A - Z for c := 'A'; c <= 'Z'; c++ { - keyCodeToNameSafari[int(c)] = string(c) + keyCodeToNameEdge[int(c)] = string(c) } // Function keys for i := 1; i <= 12; i++ { - keyCodeToNameSafari[0x70+i-1] = "F" + strconv.Itoa(i) + keyCodeToNameEdge[0x70+i-1] = "F" + strconv.Itoa(i) } } @@ -205,8 +205,8 @@ var keyToCodes = map[Key][]string{ {{end}} } -var keyCodeToKeySafari = map[int]Key{ -{{range $code, $name := .KeyCodeToNameSafari}}{{$code}}: Key{{$name}}, +var keyCodeToKeyEdge = map[int]Key{ +{{range $code, $name := .KeyCodeToNameEdge}}{{$code}}: Key{{$name}}, {{end}} } ` @@ -353,7 +353,7 @@ func main() { "Notice": notice, "BuildTag": buildTag, "NameToCodes": nameToCodes, - "KeyCodeToNameSafari": keyCodeToNameSafari, + "KeyCodeToNameEdge": keyCodeToNameEdge, "Codes": codes, "KeyNames": names, "LastKeyName": names[len(names)-1], diff --git a/internal/ui/input_js.go b/internal/ui/input_js.go index bcf5735c6..825119a10 100644 --- a/internal/ui/input_js.go +++ b/internal/ui/input_js.go @@ -29,7 +29,7 @@ func (m mockRWLock) RUnlock() {} type Input struct { keyPressed map[string]bool - keyPressedSafari map[int]bool + keyPressedEdge map[int]bool mouseButtonPressed map[int]bool cursorX int cursorY int @@ -51,12 +51,12 @@ func (i *Input) IsKeyPressed(key Key) bool { } } } - if i.keyPressedSafari != nil { - for c, k := range keyCodeToKeySafari { + if i.keyPressedEdge != nil { + for c, k := range keyCodeToKeyEdge { if k != key { continue } - if i.keyPressedSafari[c] { + if i.keyPressedEdge[c] { return true } } @@ -99,18 +99,18 @@ func (i *Input) keyUp(code string) { i.keyPressed[code] = false } -func (i *Input) keyDownSafari(code int) { - if i.keyPressedSafari == nil { - i.keyPressedSafari = map[int]bool{} +func (i *Input) keyDownEdge(code int) { + if i.keyPressedEdge == nil { + i.keyPressedEdge = map[int]bool{} } - i.keyPressedSafari[code] = true + i.keyPressedEdge[code] = true } -func (i *Input) keyUpSafari(code int) { - if i.keyPressedSafari == nil { - i.keyPressedSafari = map[int]bool{} +func (i *Input) keyUpEdge(code int) { + if i.keyPressedEdge == nil { + i.keyPressedEdge = map[int]bool{} } - i.keyPressedSafari[code] = false + i.keyPressedEdge[code] = false } func (i *Input) mouseDown(code int) { diff --git a/internal/ui/keys_js.go b/internal/ui/keys_js.go index 9aab62b7b..b606eccde 100644 --- a/internal/ui/keys_js.go +++ b/internal/ui/keys_js.go @@ -255,7 +255,7 @@ var keyToCodes = map[Key][]string{ }, } -var keyCodeToKeySafari = map[int]Key{ +var keyCodeToKeyEdge = map[int]Key{ 8: KeyBackspace, 9: KeyTab, 13: KeyEnter, diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 6ea5f043d..fc8a1fb5d 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -246,13 +246,12 @@ func initialize() error { canvas.Call("addEventListener", "keydown", func(e *js.Object) { c := e.Get("code") if c == js.Undefined { - // TODO: Now this is used for Edge, not Safari. Rename functions. code := e.Get("keyCode").Int() - if keyCodeToKeySafari[code] == KeyUp || - keyCodeToKeySafari[code] == KeyDown || - keyCodeToKeySafari[code] == KeyLeft || - keyCodeToKeySafari[code] == KeyRight { - currentInput.keyDownSafari(code) + if keyCodeToKeyEdge[code] == KeyUp || + keyCodeToKeyEdge[code] == KeyDown || + keyCodeToKeyEdge[code] == KeyLeft || + keyCodeToKeyEdge[code] == KeyRight { + currentInput.keyDownEdge(code) } return } @@ -274,9 +273,9 @@ func initialize() error { canvas.Call("addEventListener", "keyup", func(e *js.Object) { e.Call("preventDefault") if e.Get("code") == js.Undefined { - // Assume that UA is Safari. + // Assume that UA is Edge. code := e.Get("keyCode").Int() - currentInput.keyUpSafari(code) + currentInput.keyUpEdge(code) } code := e.Get("code").String() currentInput.keyUp(code)