aboutsummaryrefslogtreecommitdiff
path: root/src/content/domains
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-03 12:32:32 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:58:59 +0000
commitb496cea5827165bd23a503231f94f708a976cad4 (patch)
treef6d8ec1bd42c8d6d43143c1b62d48b9f4a1d62c4 /src/content/domains
parent62a86c525378610444a9976dd4409ea207174d20 (diff)
Make KeySequence class
Diffstat (limited to 'src/content/domains')
-rw-r--r--src/content/domains/KeySequence.ts60
1 files changed, 25 insertions, 35 deletions
diff --git a/src/content/domains/KeySequence.ts b/src/content/domains/KeySequence.ts
index 61ceab1..abae61a 100644
--- a/src/content/domains/KeySequence.ts
+++ b/src/content/domains/KeySequence.ts
@@ -1,14 +1,9 @@
import Key from './Key';
export default class KeySequence {
- private keys: Key[];
-
- private constructor(keys: Key[]) {
- this.keys = keys;
- }
-
- static from(keys: Key[]): KeySequence {
- return new KeySequence(keys);
+ constructor(
+ public readonly keys: Key[],
+ ) {
}
push(key: Key): number {
@@ -31,34 +26,29 @@ export default class KeySequence {
return true;
}
- getKeyArray(): Key[] {
- return this.keys;
- }
-}
-
-export const fromMapKeys = (keys: string): KeySequence => {
- const fromMapKeysRecursive = (
- remainings: string, mappedKeys: Key[],
- ): Key[] => {
- if (remainings.length === 0) {
- return mappedKeys;
- }
-
- let nextPos = 1;
- if (remainings.startsWith('<')) {
- let ltPos = remainings.indexOf('>');
- if (ltPos > 0) {
- nextPos = ltPos + 1;
+ static fromMapKeys(keys: string): KeySequence {
+ const fromMapKeysRecursive = (
+ remaining: string, mappedKeys: Key[],
+ ): Key[] => {
+ if (remaining.length === 0) {
+ return mappedKeys;
}
- }
- return fromMapKeysRecursive(
- remainings.slice(nextPos),
- mappedKeys.concat([Key.fromMapKey(remainings.slice(0, nextPos))])
- );
- };
+ let nextPos = 1;
+ if (remaining.startsWith('<')) {
+ let ltPos = remaining.indexOf('>');
+ if (ltPos > 0) {
+ nextPos = ltPos + 1;
+ }
+ }
- let data = fromMapKeysRecursive(keys, []);
- return KeySequence.from(data);
-};
+ return fromMapKeysRecursive(
+ remaining.slice(nextPos),
+ mappedKeys.concat([Key.fromMapKey(remaining.slice(0, nextPos))])
+ );
+ };
+ let data = fromMapKeysRecursive(keys, []);
+ return new KeySequence(data);
+ }
+}