From d6491011cf30ad9ff830cbea02333cc969f414e9 Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Mon, 13 Aug 2018 18:50:54 -0700 Subject: [PATCH] fix: mapped leaderKey loses it's default functionality. closes #2932. --- src/actions/base.ts | 60 +++++++++++++++------------------ test/actions/baseAction.test.ts | 10 +++++- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/actions/base.ts b/src/actions/base.ts index 8315c4af700..5b91ace3b31 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -77,10 +77,10 @@ export class BaseAction { return true; } - public static CompareKeypressSequence(one: string[] | string[][], two: string[]): boolean { - if (BaseAction.is2DArray(one)) { - for (const sequence of one) { - if (BaseAction.CompareKeypressSequence(sequence, two)) { + public static CompareKeypressSequence(a: string[] | string[][], b: string[]): boolean { + if (BaseAction.is2DArray(a)) { + for (const sequence of a) { + if (BaseAction.CompareKeypressSequence(sequence, b)) { return true; } } @@ -88,57 +88,51 @@ export class BaseAction { return false; } - if (one.length !== two.length) { + if (a.length !== b.length) { return false; } const isSingleNumber: RegExp = /^[0-9]$/; const isSingleAlpha: RegExp = /^[a-zA-Z]$/; - for (let i = 0, j = 0; i < one.length; i++, j++) { - const left = one[i], - right = two[j]; + for (let i = 0; i < a.length; i++) { + const left = a[i], + right = b[i]; - if (left === '') { - continue; - } - if (right === '') { + if (left === right) { continue; } - if (left === '' && isSingleNumber.test(right)) { - continue; - } - if (right === '' && isSingleNumber.test(left)) { + if (left === '' || right === '') { continue; } - if (left === '' && isSingleAlpha.test(right)) { - continue; - } - if (right === '' && isSingleAlpha.test(left)) { + if ( + (left === '' && isSingleNumber.test(right)) || + (right === '' && isSingleNumber.test(left)) + ) { continue; } - if (left === '' && !Notation.IsControlKey(right)) { - continue; - } - if (right === '' && !Notation.IsControlKey(left)) { + if ( + (left === '' && isSingleAlpha.test(right)) || + (right === '' && isSingleAlpha.test(left)) + ) { continue; } - if (left === '' && right === configuration.leader) { - continue; - } - if (right === '' && left === configuration.leader) { + if ( + (left === '' && !Notation.IsControlKey(right)) || + (right === '' && !Notation.IsControlKey(left)) + ) { continue; } - if (left === configuration.leader) { - return false; - } - if (right === configuration.leader) { - return false; + if ( + (left === '' && right === configuration.leader) || + (right === '' && left === configuration.leader) + ) { + continue; } if (left !== right) { diff --git a/test/actions/baseAction.test.ts b/test/actions/baseAction.test.ts index ad01878bb89..048aaec9f3e 100644 --- a/test/actions/baseAction.test.ts +++ b/test/actions/baseAction.test.ts @@ -5,6 +5,7 @@ import { BaseAction } from '../../src/actions/base'; import { VimState } from '../../src/state/vimState'; import { setupWorkspace, cleanUpWorkspace } from './../testUtils'; import { ModeName } from '../../src/mode/mode'; +import { Configuration } from '../testConfiguration'; class TestAction1D extends BaseAction { keys = ['a', 'b']; @@ -17,12 +18,16 @@ class TestAction2D extends BaseAction { } suite('base action', () => { + const leaderKey = '/'; const action1D = new TestAction1D(); const action2D = new TestAction2D(); let vimState: VimState; suiteSetup(async () => { - await setupWorkspace(); + let configuration = new Configuration(); + configuration.leader = leaderKey; + + await setupWorkspace(configuration); vimState = new VimState(vscode.window.activeTextEditor!); }); @@ -31,6 +36,9 @@ suite('base action', () => { test('compare key presses', () => { let testCases: Array<[string[] | string[][], string[], boolean]> = [ [['a'], ['a'], true], + [['1'], [''], true], + [[''], [leaderKey], true], + [['A'], [''], true], [[['a']], ['a'], true], [[['a'], ['b']], ['b'], true], [[['a'], ['b']], ['c'], false],