A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
55 lines
1.1 KiB
5 years ago
|
import Key from '../../shared/settings/Key';
|
||
5 years ago
|
|
||
|
export default class KeySequence {
|
||
5 years ago
|
constructor(
|
||
|
public readonly keys: Key[],
|
||
|
) {
|
||
5 years ago
|
}
|
||
|
|
||
|
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) {
|
||
5 years ago
|
if (!this.keys[i].equals(o.keys[i])) {
|
||
5 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
5 years ago
|
static fromMapKeys(keys: string): KeySequence {
|
||
|
const fromMapKeysRecursive = (
|
||
|
remaining: string, mappedKeys: Key[],
|
||
|
): Key[] => {
|
||
|
if (remaining.length === 0) {
|
||
|
return mappedKeys;
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
let nextPos = 1;
|
||
|
if (remaining.startsWith('<')) {
|
||
|
let ltPos = remaining.indexOf('>');
|
||
|
if (ltPos > 0) {
|
||
|
nextPos = ltPos + 1;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
return fromMapKeysRecursive(
|
||
|
remaining.slice(nextPos),
|
||
|
mappedKeys.concat([Key.fromMapKey(remaining.slice(0, nextPos))])
|
||
|
);
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
let data = fromMapKeysRecursive(keys, []);
|
||
|
return new KeySequence(data);
|
||
|
}
|
||
|
}
|