From 3db019812aaeb3dc68902f4445ae82f38f68c0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kiss?= Date: Mon, 17 Jul 2017 00:48:31 +0200 Subject: [PATCH] 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 --- .../src/components/keymap/header/keymap-header.component.ts | 4 +++- shared/src/store/reducers/user-configuration.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/src/components/keymap/header/keymap-header.component.ts b/shared/src/components/keymap/header/keymap-header.component.ts index 008be348..a6983bb1 100644 --- a/shared/src/components/keymap/header/keymap-header.component.ts +++ b/shared/src/components/keymap/header/keymap-header.component.ts @@ -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; } diff --git a/shared/src/store/reducers/user-configuration.ts b/shared/src/store/reducers/user-configuration.ts index 28ce6d18..0b752cfe 100644 --- a/shared/src/store/reducers/user-configuration.ts +++ b/shared/src/store/reducers/user-configuration.ts @@ -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)) {