Skip to content

Commit

Permalink
Handle AltGr (non-US keyboards) on Windows Chrome/IE properly, fix re…
Browse files Browse the repository at this point in the history
  • Loading branch information
pasieronen committed Aug 29, 2014
1 parent 1a08325 commit 06e61f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/jqconsole.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class JQConsole
# We let the browser take over during output mode.
# Skip everything when a modifier key other than shift is held.
# Allow alt key to pass through for unicode & multibyte characters.
if @state == STATE_OUTPUT or event.metaKey or event.ctrlKey
if @state == STATE_OUTPUT or event.metaKey or (event.ctrlKey and !event.altKey)
return true

# IE & Chrome capture non-control characters and Enter.
Expand Down
3 changes: 2 additions & 1 deletion test/setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ window.jqconsoleSetup = ->
$container.appendTo('body')
jqconsole = new JQConsole($container, 'header', 'prompt_label', 'prompt_continue')
typer =
typeA: ->
typeA: (options = {}) ->
e = $.Event('keypress')
e.which = 'a'.charCodeAt(0)
e[k] = v for k, v of options
jqconsole.$input_source.trigger e

keyDown: (code, options = {}) ->
Expand Down
13 changes: 12 additions & 1 deletion test/shortcuts-test.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{jqconsole, typer: {keyDown}} = jqconsoleSetup()
{jqconsole, typer: {typeA, keyDown}} = jqconsoleSetup()

describe 'Shortcuts', ->
describe '#RegisterShortcut', ->
Expand Down Expand Up @@ -58,3 +58,14 @@ describe 'Shortcuts', ->
counter++
keyDown 'a'.charCodeAt(0), metaKey: on
ok counter

it 'altgr inputs character instead of invoking shortcut', ->
jqconsole.Prompt true, ->
counter = 0
jqconsole.RegisterShortcut 'a', ->
strictEqual this, jqconsole
counter++
keyDown 'a'.charCodeAt(0), ctrlKey: on, altKey: on
typeA(altKey: on, ctrlKey: on)
equal counter, 0
equal jqconsole.$prompt.text().trim(), 'prompt_labela'

0 comments on commit 06e61f7

Please sign in to comment.