aboutsummaryrefslogtreecommitdiff
path: root/src/shared/settings
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/settings')
-rw-r--r--src/shared/settings/Key.ts22
-rw-r--r--src/shared/settings/KeySequence.ts54
2 files changed, 17 insertions, 59 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
deleted file mode 100644
index abae61a..0000000
--- a/src/shared/settings/KeySequence.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import Key from './Key';
-
-export default class KeySequence {
- constructor(
- public readonly keys: Key[],
- ) {
- }
-
- push(key: Key): number {
- return this.keys.push(key);
- }
-
- length(): number {
- return this.keys.length;
- }
-
- startsWith(o: KeySequence): boolean {
- if (this.keys.length < o.keys.length) {
- return false;
- }
- for (let i = 0; i < o.keys.length; ++i) {
- if (!this.keys[i].equals(o.keys[i])) {
- return false;
- }
- }
- return true;
- }
-
- static fromMapKeys(keys: string): KeySequence {
- const fromMapKeysRecursive = (
- remaining: string, mappedKeys: Key[],
- ): Key[] => {
- if (remaining.length === 0) {
- return mappedKeys;
- }
-
- let nextPos = 1;
- if (remaining.startsWith('<')) {
- let ltPos = remaining.indexOf('>');
- if (ltPos > 0) {
- nextPos = ltPos + 1;
- }
- }
-
- return fromMapKeysRecursive(
- remaining.slice(nextPos),
- mappedKeys.concat([Key.fromMapKey(remaining.slice(0, nextPos))])
- );
- };
-
- let data = fromMapKeysRecursive(keys, []);
- return new KeySequence(data);
- }
-}