feat(keymap): Keymap abbr should be only number or ASCII char (#360)

* feat(keymap): Keymap abbr should be only number or ASCII char

close #341

* fix(keymap): Allow '1' when generate keymap abbreviation
This commit is contained in:
Róbert Kiss
2017-07-17 00:48:31 +02:00
committed by László Monda
parent c1f96ae820
commit 3db019812a
2 changed files with 4 additions and 2 deletions

View File

@@ -72,7 +72,9 @@ export class KeymapHeaderComponent implements OnChanges {
}
editKeymapAbbr(newAbbr: string) {
if (newAbbr.length !== 3) {
const regexp = new RegExp(/^[a-zA-Z\d]+$/g);
if (newAbbr.length < 1 || newAbbr.length > 3 || !regexp.test(newAbbr)) {
this.renderer.setElementProperty(this.keymapAbbr.nativeElement, 'value', this.keymap.abbreviation);
return;
}

View File

@@ -274,7 +274,7 @@ export function getMacro(id: number) {
}
function generateAbbr(keymaps: Keymap[], abbr: string): string {
const chars: string[] = '23456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const chars: string[] = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let position = 0;
while (keymaps.some((keymap: Keymap) => keymap.abbreviation === abbr)) {