Bug 1268450 - Accept loose digits for azerty keyboards. r=jryans

This commit is contained in:
Alexandre Poirot 2016-05-19 16:13:00 -04:00
parent 1915a59e3c
commit f4727ff5fd
2 changed files with 41 additions and 1 deletions

View File

@ -187,7 +187,12 @@ KeyShortcuts.prototype = {
if (shortcut.keyCode) {
return event.keyCode == shortcut.keyCode;
}
return event.key.toLowerCase() == shortcut.key;
// For character keys, we match if the final character is the expected one.
// But for digits we also accept indirect match to please azerty keyboard,
// which requires Shift to be pressed to get digits.
return event.key.toLowerCase() == shortcut.key ||
( shortcut.key.match(/[0-9]/) &&
event.keyCode == shortcut.key.charCodeAt(0) );
},
handleEvent(event) {

View File

@ -10,6 +10,7 @@ add_task(function* () {
yield testSimple(shortcuts);
yield testNonLetterCharacter(shortcuts);
yield testMixup(shortcuts);
yield testLooseDigits(shortcuts);
yield testExactModifiers(shortcuts);
yield testLooseShiftModifier(shortcuts);
yield testStrictLetterShiftModifier(shortcuts);
@ -95,6 +96,40 @@ function testMixup(shortcuts) {
ok(hitSecond, "Got the second shortcut notified once it is actually fired");
}
// On azerty keyboard, digits are only available by pressing Shift/Capslock,
// but we accept them even if we omit doing that.
function testLooseDigits(shortcuts) {
info("Test Loose digits");
let onKey = once(shortcuts, "0", (key, event) => {
is(event.key, "à");
ok(!event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(!event.shiftKey);
});
// Simulate a press on the "0" key, without shift pressed on a french
// keyboard
EventUtils.synthesizeKey(
"à",
{ keyCode: 48 },
window);
yield onKey;
onKey = once(shortcuts, "0", (key, event) => {
is(event.key, "0");
ok(!event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(event.shiftKey);
});
// Simulate the same press with shift pressed
EventUtils.synthesizeKey(
"0",
{ keyCode: 48, shiftKey: true },
window);
yield onKey;
}
// Test that shortcuts is notified only when the modifiers match exactly
function testExactModifiers(shortcuts) {
info("Test exact modifiers match");