diff --git a/frontend_tests/node_tests/keydown_util.js b/frontend_tests/node_tests/keydown_util.js index 141e76af68..57ea24916a 100644 --- a/frontend_tests/node_tests/keydown_util.js +++ b/frontend_tests/node_tests/keydown_util.js @@ -3,24 +3,35 @@ set_global('$', global.make_zjquery()); zrequire('keydown_util'); run_test('test_early_returns', () => { - var stub = $.create('stub'); - var opts = { + const stub = $.create('stub'); + const opts = { elem: stub, - handlers: {}, + handlers: { + left_arrow: () => { + throw Error('do not dispatch this with alt key'); + }, + }, }; keydown_util.handle(opts); - var keydown_f = stub.keydown; + const keydown_f = stub.keydown; - var e1 = { + const e1 = { which: 17, // not in keys }; keydown_f(e1); - var e2 = { + const e2 = { which: 13, // no handler }; keydown_f(e2); + + const e3 = { + which: 37, + altKey: true, // let browser handle + }; + + keydown_f(e3); }); diff --git a/static/js/keydown_util.js b/static/js/keydown_util.js index 032871a1fb..17ecf4260c 100644 --- a/static/js/keydown_util.js +++ b/static/js/keydown_util.js @@ -18,6 +18,10 @@ exports.handle = function (opts) { opts.elem.keydown(function (e) { var key = e.which || e.keyCode; + if (e.altKey || e.ctrlKey || e.shiftKey) { + return; + } + var key_name = keys[key]; if (!key_name) {