Skip to content
8 changes: 4 additions & 4 deletions coffee/commandbox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class g.CommandBox

handleKey : (key) ->
event.stopPropagation()
if @value().length == 0 and ( key.code == "BS" or key.code == "DEL" )
if @value().length == 0 and ( key.code == "Backspace" or key.code == "Delete" )
event.preventDefault()
@reqEscape()
return

if key.code == "CR"
if key.code == "Enter"
@fixedListener?( @value() )
@detachFrom()
return
Expand All @@ -81,11 +81,11 @@ class g.CommandBox
return

onKeyDown : (e) ->
if g.KeyManager.isOnlyModifier( e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
if g.KeyManager.isOnlyModifier( e.key, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
g.logger.d "getHandlableKey:only modefier"
return

code = g.KeyManager.getLocalKeyCode( e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
code = g.KeyManager.getLocalKeyCode( e.key, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
unless code?
g.logger.d "getHandlableKey:cant be handled"
return
Expand Down
4 changes: 2 additions & 2 deletions coffee/eventhandler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class g.EventHandler
# decide whether to post the key event and do some pre-post process
# return true if the key event can be posted.
getHandlableKey : (e) ->
if g.KeyManager.isOnlyModifier( e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
if g.KeyManager.isOnlyModifier( e.key, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
g.logger.d "getHandlableKey:only modifier"
return undefined

code = g.KeyManager.getLocalKeyCode( e.keyIdentifier, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
code = g.KeyManager.getLocalKeyCode( e.key, e.ctrlKey, e.shiftKey, e.altKey, e.metaKey )
unless code?
g.logger.d "getHandlableKey:cant be handled"
return undefined
Expand Down
196 changes: 72 additions & 124 deletions coffee/key.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ this.vichrome ?= {}
g = this.vichrome
g.key = {}

g.key.keyCodes =
ESC : 27
TAB : 9
SHIFT : 16
BS : 8
ALT : 18
CTRL : 17
META : 91
DEL : 46
CR : 13
SPACE : 32
LEFT : 128
UP : 129
RIGHT : 130
DOWN : 131
g.key.keyCodes =
Escape : 27
Tab : 9
Shift : 16
Backspace : 8
Alt : 18
Control : 17
Meta : 91
Delete : 46
Enter : 13
Space : 32
ArrowRight: 128
ArrowUp : 129
ArrowLeft : 130
ArrowDown : 131
F1 : 132
F2 : 133
F3 : 134
Expand All @@ -30,107 +30,50 @@ g.key.keyCodes =
F11 : 142
F12 : 143

g.key.keyIdentifier =
"U+0031" : "1"
"U+0032" : "2"
"U+0033" : "3"
"U+0034" : "4"
"U+0035" : "5"
"U+0036" : "6"
"U+0037" : "7"
"U+0038" : "8"
"U+0039" : "9"
"U+0030" : "0"
"U+0021" : "!"
"U+0022" : '"'
"U+0023" : "#"
"U+0024" : "$"
"U+0025" : "%"
"U+0026" : "&"
"U+0027" : "'"
"U+0028" : "("
"U+0029" : ")"
"U+002D" : "-"
"U+003D" : "="
"U+005E" : "^"
"U+007E" : "~"
"U+00A5" : "\\"
"U+005C" : "\\"
"U+007C" : "|"
"U+0041" : "a"
"U+0042" : "b"
"U+0043" : "c"
"U+0044" : "d"
"U+0045" : "e"
"U+0046" : "f"
"U+0047" : "g"
"U+0048" : "h"
"U+0049" : "i"
"U+004A" : "j"
"U+004B" : "k"
"U+004C" : "l"
"U+004D" : "m"
"U+004E" : "n"
"U+004F" : "o"
"U+0050" : "p"
"U+0051" : "q"
"U+0052" : "r"
"U+0053" : "s"
"U+0054" : "t"
"U+0055" : "u"
"U+0056" : "v"
"U+0057" : "w"
"U+0058" : "x"
"U+0059" : "y"
"U+005A" : "z"
"U+0040" : "@"
"U+0060" : "`"
"U+005B" : "["
"U+007B" : "{"
"U+003B" : ";"
"U+002B" : "+"
"U+003A" : ":"
"U+002A" : "*"
"U+005D" : "]"
"U+007D" : "}"
"U+002C" : ","
"U+003C" : "<"
"U+002E" : "."
"U+003E" : ">"
"U+002F" : "/"
"U+003F" : "?"
"U+005F" : "_"
"U+0020" : "SPACE"
"Left" : "LEFT"
"Down" : "DOWN"
"Up" : "UP"
"Right" : "RIGHT"
"Enter" : "CR"
"U+0008" : "BS"
"U+007F" : "DEL"
"U+0009" : "TAB"
"F1" : "F1"
"F2" : "F2"
"F3" : "F3"
"F4" : "F4"
"F5" : "F5"
"F6" : "F6"
"F7" : "F7"
"F8" : "F8"
"F9" : "F9"
"F10" : "F10"
"F11" : "F11"
"F12" : "F12"
"U+001B" : "ESC"
"Home" : "HOME"
"End" : "END"
"Control" : "CTRL"
"Shift" : "SHIFT"
"Alt" : "ALT"
"Meta" : "META"
"PageDown" : "PAGEDOWN"
"PageUp" : "PAGEUP"
"CapsLock" : "CAPSLOCK"
g.key.macOptionWithKeyIdentifier =
"¡" : "1"
"™" : "2"
"£" : "3"
"¢" : "4"
"∞" : "5"
"§" : "6"
"¶" : "7"
"•" : "8"
"ª" : "9"
"º" : "0"
"–" : "-"
"≠" : "^"
"\\" : "¥"
"œ" : "q"
"∑" : "w"
"®" : "r"
"†" : "t"
"¥" : "y"
"ø" : "o"
"π" : "p"
"“" : "@"
"‘" : "["
"å" : "a"
"ß" : "s"
"∂" : "d"
"ƒ" : "f"
"©" : "g"
"˙" : "h"
"∆" : "j"
"˚" : "k"
"¬" : "l"
"…" : ";"
"æ" : ":"
"«" : "]"
"Ω" : "z"
"≈" : "x"
"ç" : "c"
"√" : "v"
"∫" : "b"
"µ" : "m"
"≤" : ","
"≥" : "."
"÷" : "/"

g.key.winKeyIdentifier_ja =
"U+00BC":","
Expand Down Expand Up @@ -206,11 +149,11 @@ g.key.shiftWinKeyIdentifier_us =
"U+0030":")"

keyCodes = g.key.keyCodes
keyIdentifier = g.key.keyIdentifier
winKeyIdentifier_ja = g.key.winKeyIdentifier_ja
shiftWinKeyIdentifier_ja = g.key.shiftWinKeyIdentifier_ja
winKeyIdentifier_us = g.key.winKeyIdentifier_us
shiftWinKeyIdentifier_us = g.key.shiftWinKeyIdentifier_us
macOptionWithKeyIdentifier = g.key.macOptionWithKeyIdentifier
winKeyIdentifier_ja = g.key.winKeyIdentifier_ja
shiftWinKeyIdentifier_ja = g.key.shiftWinKeyIdentifier_ja
winKeyIdentifier_us = g.key.winKeyIdentifier_us
shiftWinKeyIdentifier_us = g.key.shiftWinKeyIdentifier_us
util = g.util

g.KeyManager =
Expand All @@ -227,8 +170,8 @@ g.KeyManager =
( 48 <= c <= 57 )

isOnlyModifier : (code, ctrl, shift, alt, meta) ->
switch keyCodes[@getLocalKeyCode(code, ctrl, shift, alt, meta)]
when keyCodes.CTRL, keyCodes.SHIFT, keyCodes.META, keyCodes.ALT
switch code
when "Control", "Shift", "Alt", "Meta"
return true
else
return false
Expand All @@ -247,7 +190,7 @@ g.KeyManager =
result

getLocalKeyCode : (code, ctrl, shift, alt, meta) ->
result = keyIdentifier[code]
result = code

# bull shit! fxxk windows and linux
if util.getPlatform() != "Mac"
Expand All @@ -265,11 +208,16 @@ g.KeyManager =
else
if winKeyIdentifier_us[code]?
result = winKeyIdentifier_us[code]
else
if alt
if macOptionWithKeyIdentifier[code]?
result = g.key.macOptionWithKeyIdentifier[code]

if result? and @isAlphabet result
if shift
result = result.toUpperCase()
else
result = result.toLowerCase()

result = "Space" if result == " "
result
8 changes: 4 additions & 4 deletions coffee/mode.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ class g.FMode extends g.Mode

isValidKey : (key) ->
return ( @keys.indexOf( key ) >= 0 && key.length == 1 ) ||
( key == 'BS' ) ||
( key == 'DEL' )
( key == 'Backspace' ) ||
( key == 'Delete' )

searchTarget : ->
for elem, i in @hints
Expand All @@ -397,7 +397,7 @@ class g.FMode extends g.Mode
return null

treatNewInput : (key) ->
if key == "BS" || key == "DEL"
if key == "Backspace" || key == "Delete"
if @currentInput.length == 0
g.model.enterNormalMode()
return
Expand All @@ -424,7 +424,7 @@ class g.FMode extends g.Mode
g.view.hideStatusLine()

prePostKeyEvent : (key, ctrl, alt, meta) ->
if key == "ESC" then return true
if key == "Escape" then return true
if ctrl or alt or meta then return true

key = key.toUpperCase() if g.model.getSetting("fModeIgnoreCase")
Expand Down
Loading