diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-06 21:48:14 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-06 23:05:17 +0900 |
commit | c399b992e6665f194ebe08a48aae1ede32c6767f (patch) | |
tree | 3931ea9255bd22bb27f6a5f754ab13e0dbab2cb0 /src/shared/settings/KeySequence.ts | |
parent | b5d1c06386716d50316d2e85d73b8ba406a7f932 (diff) |
Identify the key is a digit
Diffstat (limited to 'src/shared/settings/KeySequence.ts')
-rw-r--r-- | src/shared/settings/KeySequence.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/settings/KeySequence.ts b/src/shared/settings/KeySequence.ts index abae61a..de1c6bb 100644 --- a/src/shared/settings/KeySequence.ts +++ b/src/shared/settings/KeySequence.ts @@ -26,6 +26,21 @@ export default class KeySequence { return true; } + isDigitOnly(): boolean { + return this.keys.every(key => key.isDigit()); + } + + splitNumericPrefix(): [KeySequence, KeySequence] { + let nonDigitIndex = this.keys.findIndex(key => !key.isDigit()); + if (nonDigitIndex === -1) { + return [this, new KeySequence([])]; + } + return [ + new KeySequence(this.keys.slice(0, nonDigitIndex)), + new KeySequence(this.keys.slice(nonDigitIndex)), + ]; + } + static fromMapKeys(keys: string): KeySequence { const fromMapKeysRecursive = ( remaining: string, mappedKeys: Key[], |