From 2d9b1501c6edcf9b342667e83b4ca7534be683f4 Mon Sep 17 00:00:00 2001 From: Vuong <3168632+vuon9@users.noreply.github.com> Date: Mon, 22 Nov 2021 15:38:52 +0700 Subject: [PATCH] Fix parseKeys related to price alert open action (#290) * Fix parseKeys related to price alert open action * Trim s before checking length Co-authored-by: Simon Roberts --- cointop/keybindings.go | 43 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/cointop/keybindings.go b/cointop/keybindings.go index eb1af05..75c5a55 100644 --- a/cointop/keybindings.go +++ b/cointop/keybindings.go @@ -51,28 +51,31 @@ func (ct *Cointop) ParseKeys(s string) (interface{}, tcell.ModMask) { mod := tcell.ModNone // translate legacy and special names for keys - keyName := strings.TrimSpace(strings.Replace(s, "+", "-", -1)) - split := strings.Split(keyName, "-") - if len(split) > 1 { - m := strings.ToLower(strings.TrimSpace(split[0])) - k := strings.TrimSpace(split[1]) - k = keyMap(k) - if k == " " { - k = "Space" // fix mod+space - } + s = strings.TrimSpace(s) + keyName := keyMap(s) + if len(s) > 1 { + keyName := strings.Replace(s, "+", "-", -1) + + split := strings.Split(keyName, "-") + if len(split) > 1 { + m := strings.ToLower(strings.TrimSpace(split[0])) + k := strings.TrimSpace(split[1]) + k = keyMap(k) + if k == " " { + k = "Space" // fix mod+space + } - if m == "alt" { - mod = tcell.ModAlt - keyName = k - } else if m == "ctrl" { - // let the lookup handle it - keyName = m + "-" + k - } else { - keyName = m + "-" + k + if m == "alt" { + mod = tcell.ModAlt + keyName = k + } else if m == "ctrl" { + // let the lookup handle it + keyName = m + "-" + k + } else { + keyName = m + "-" + k + } + // TODO: other mods? } - // TODO: other mods? - } else { - keyName = keyMap(keyName) } // First try looking up keyname directly