aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shared/settings/Key.ts22
-rw-r--r--src/shared/settings/KeySequence.ts15
2 files changed, 32 insertions, 5 deletions
diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts
index b11eeb2..3a3eb3b 100644
--- a/src/shared/settings/Key.ts
+++ b/src/shared/settings/Key.ts
@@ -1,3 +1,5 @@
+const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
+
export default class Key {
public readonly key: string;
@@ -9,12 +11,18 @@ export default class Key {
public readonly meta: boolean;
- constructor({ key, shift, ctrl, alt, meta }: {
+ constructor({
+ key,
+ shift = false,
+ ctrl = false,
+ alt = false,
+ meta = false,
+ }: {
key: string;
- shift: boolean;
- ctrl: boolean;
- alt: boolean;
- meta: boolean;
+ shift?: boolean;
+ ctrl?: boolean;
+ alt?: boolean;
+ meta?: boolean;
}) {
this.key = key;
this.shift = shift;
@@ -51,6 +59,10 @@ export default class Key {
});
}
+ isDigit(): boolean {
+ return digits.includes(this.key);
+ }
+
equals(key: Key) {
return this.key === key.key &&
this.ctrl === key.ctrl &&
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[],