feat(key_event): alias esc to escape

fixes #2010
This commit is contained in:
Victor Berchet 2015-05-20 08:51:31 +02:00
parent 9988471fb8
commit 10bc7e948c
2 changed files with 19 additions and 3 deletions

View File

@ -39,15 +39,16 @@ export class KeyEventsPlugin extends EventManagerPlugin {
} }
static parseEventName(eventName: string) /* {'domEventName': string, 'fullKey': string} */ { static parseEventName(eventName: string) /* {'domEventName': string, 'fullKey': string} */ {
eventName = eventName.toLowerCase(); var parts = eventName.toLowerCase().split('.');
var parts = eventName.split('.');
var domEventName = ListWrapper.removeAt(parts, 0); var domEventName = ListWrapper.removeAt(parts, 0);
if ((parts.length === 0) || if ((parts.length === 0) ||
!(StringWrapper.equals(domEventName, 'keydown') || !(StringWrapper.equals(domEventName, 'keydown') ||
StringWrapper.equals(domEventName, 'keyup'))) { StringWrapper.equals(domEventName, 'keyup'))) {
return null; return null;
} }
var key = ListWrapper.removeLast(parts);
var key = KeyEventsPlugin._normalizeKey(ListWrapper.removeLast(parts));
var fullKey = ''; var fullKey = '';
ListWrapper.forEach(modifierKeys, (modifierName) => { ListWrapper.forEach(modifierKeys, (modifierName) => {
@ -94,4 +95,14 @@ export class KeyEventsPlugin extends EventManagerPlugin {
} }
}; };
} }
static _normalizeKey(keyName: string): string {
// TODO: switch to a StringMap if the mapping grows too much
switch (keyName) {
case 'esc':
return 'escape';
default:
return keyName;
}
}
} }

View File

@ -65,5 +65,10 @@ export function main() {
}); });
it('should alias esc to escape', () => {
expect(KeyEventsPlugin.parseEventName('keyup.control.esc'))
.toEqual(KeyEventsPlugin.parseEventName('keyup.control.escape'));
});
}); });
} }