From ab58c5edb79b4a5aa347e80deaeb612216a9d34e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Dec 2019 15:08:07 +0900 Subject: Add numeric prefix to repeat a command --- src/content/usecases/KeymapUseCase.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/content/usecases') diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index f7de334..fab13f5 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -36,13 +36,13 @@ export default class KeymapUseCase { } // eslint-disable-next-line max-statements - nextOps(key: Key): operations.Operation[] { + nextOps(key: Key): { count: number, op: operations.Operation } | null { let sequence = this.repository.enqueueKey(key); let baseSequence = sequence.trimNumericPrefix(); if (baseSequence.length() === 1 && this.blacklistKey(key)) { // ignore if the input starts with black list keys this.repository.clear(); - return []; + return null; } let keymaps = this.keymapEntityMap(); @@ -53,21 +53,21 @@ export default class KeymapUseCase { sequence.length() === matched[0][0].length()) { // keys are matched with an operation this.repository.clear(); - return [matched[0][1]]; + return { count: 1, op: matched[0][1] }; } else if ( baseMatched.length === 1 && baseSequence.length() === baseMatched[0][0].length()) { // keys are matched with an operation with a numeric prefix this.repository.clear(); - return Array(sequence.repeatCount()).fill(baseMatched[0][1]); + return { count: sequence.repeatCount(), op: baseMatched[0][1] }; } else if (matched.length >= 1 || baseMatched.length >= 1) { // keys are matched with an operation's prefix - return []; + return null; } // matched with no operations this.repository.clear(); - return []; + return null; } private keymapEntityMap(): [KeySequence, operations.Operation][] { -- cgit v1.2.3