Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mapped leaderKey loses it's default functionality. closes #2932. #2957

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 27 additions & 33 deletions src/actions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,68 +77,62 @@ 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;
}
}

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 === '<any>') {
continue;
}
if (right === '<any>') {
if (left === right) {
continue;
}

if (left === '<number>' && isSingleNumber.test(right)) {
continue;
}
if (right === '<number>' && isSingleNumber.test(left)) {
if (left === '<any>' || right === '<any>') {
continue;
}

if (left === '<alpha>' && isSingleAlpha.test(right)) {
continue;
}
if (right === '<alpha>' && isSingleAlpha.test(left)) {
if (
(left === '<number>' && isSingleNumber.test(right)) ||
(right === '<number>' && isSingleNumber.test(left))
) {
continue;
}

if (left === '<character>' && !Notation.IsControlKey(right)) {
continue;
}
if (right === '<character>' && !Notation.IsControlKey(left)) {
if (
(left === '<alpha>' && isSingleAlpha.test(right)) ||
(right === '<alpha>' && isSingleAlpha.test(left))
) {
continue;
}

if (left === '<leader>' && right === configuration.leader) {
continue;
}
if (right === '<leader>' && left === configuration.leader) {
if (
(left === '<character>' && !Notation.IsControlKey(right)) ||
(right === '<character>' && !Notation.IsControlKey(left))
) {
continue;
}

if (left === configuration.leader) {
return false;
}
if (right === configuration.leader) {
return false;
if (
(left === '<leader>' && right === configuration.leader) ||
(right === '<leader>' && left === configuration.leader)
) {
continue;
}

if (left !== right) {
Expand Down
10 changes: 9 additions & 1 deletion test/actions/baseAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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!);
});

Expand All @@ -31,6 +36,9 @@ suite('base action', () => {
test('compare key presses', () => {
let testCases: Array<[string[] | string[][], string[], boolean]> = [
[['a'], ['a'], true],
[['1'], ['<number>'], true],
[['<leader>'], [leaderKey], true],
[['A'], ['<alpha>'], true],
[[['a']], ['a'], true],
[[['a'], ['b']], ['b'], true],
[[['a'], ['b']], ['c'], false],
Expand Down