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: fixes circular dependency between notation and configuration #2277

Merged
merged 1 commit into from
Jan 10, 2018
Merged
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
2 changes: 1 addition & 1 deletion extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export async function activate(context: vscode.ExtensionContext) {
const mh = await getAndUpdateModeHandler();
if (args.after) {
for (const key of args.after) {
await mh.handleKeyEvent(Notation.NormalizeKey(key));
await mh.handleKeyEvent(Notation.NormalizeKey(key, Configuration.leader));
}
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/cmd_line/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class FileCommand extends node.CommandBase {
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile');
await vscode.commands.executeCommand('workbench.action.closeOtherEditors');
}

return;
} else if (this._arguments.name === '') {
if (this._arguments.position === FilePosition.NewWindow) {
Expand Down
12 changes: 4 additions & 8 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ class ConfigurationClass {
}
}

// resolve and normalize leader key
this.leader =
this.leader.toLocaleLowerCase() === '<leader>'
? this.leaderDefault
: Notation.NormalizeKey(this.leader);
this.leader = Notation.NormalizeKey(this.leader, this.leaderDefault);

// normalize keys
const keybindingList: IKeyRemapping[][] = [
Expand All @@ -102,13 +98,13 @@ class ConfigurationClass {
for (let remapping of keybindings) {
if (remapping.before) {
remapping.before.forEach(
(key, idx) => (remapping.before[idx] = Notation.NormalizeKey(key))
(key, idx) => (remapping.before[idx] = Notation.NormalizeKey(key, this.leader))
);
}

if (remapping.after) {
remapping.after.forEach(
(key, idx) => (remapping.after![idx] = Notation.NormalizeKey(key))
(key, idx) => (remapping.after![idx] = Notation.NormalizeKey(key, this.leader))
);
}
}
Expand All @@ -129,7 +125,7 @@ class ConfigurationClass {
}

this.boundKeyCombinations.push({
key: Notation.NormalizeKey(key),
key: Notation.NormalizeKey(key, this.leader),
command: keybinding.command,
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/configuration/notation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as _ from 'lodash';

import { Configuration } from './configuration';

export class Notation {
// Mapping from the nomalized string to regex strings that could match it.
private static _notationMap: { [key: string]: string[] } = {
Expand All @@ -17,7 +15,7 @@ export class Notation {
* (e.g. <ctrl+x>, Ctrl+x, <c-x> normalized to <C-x>)
* and resolves special cases such as '<leader>'
*/
public static NormalizeKey(key: string): string {
public static NormalizeKey(key: string, leaderKey: string): string {
if (!this.isSurroundedByAngleBrackets(key) && key.length > 1) {
key = `<${key.toLocaleLowerCase()}>`;
}
Expand All @@ -32,7 +30,7 @@ export class Notation {
}

if (key.toLocaleLowerCase() === '<leader>') {
return Configuration.leader;
return leaderKey;
}

if (_.includes(['<up>', '<down>', '<left>', '<right>'], key.toLocaleLowerCase())) {
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const ErrorMessage: IErrorMessage = {
208: 'Error writing to file',
348: 'No string under cursor',
444: 'Cannot close last window',
492: 'Not an editor command',
488: 'Trailing characters',
492: 'Not an editor command',
};

export class VimError extends Error {
Expand Down
6 changes: 5 additions & 1 deletion test/notation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { Notation } from '../src/configuration/notation';

suite('Notation', () => {
test('Normalize', () => {
let leaderKey = '//';
let testCases = {
'<cTrL+w>': '<C-w>',
'cTrL+x': '<C-x>',
'CtRl+y': '<C-y>',
'c-z': '<C-z>',
'<CmD+a>': '<D-a>',
eScapE: '<Esc>',
'<LeAder>': '//',
};

for (const test in testCases) {
if (testCases.hasOwnProperty(test)) {
let expected = testCases[test];

let actual = Notation.NormalizeKey(test);
let actual = Notation.NormalizeKey(test, leaderKey);
assert.equal(actual, expected);
}
}
Expand Down