Skip to content

Commit

Permalink
Merge pull request #2782 from VSCodeVim/remapping
Browse files Browse the repository at this point in the history
refactor: simplify normalizekey() by using existing map
  • Loading branch information
jpoon authored Jun 27, 2018
2 parents 68e0566 + 5695404 commit 4b79f1a
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/configuration/notation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,27 @@ export class Notation {
Esc: ['escape', 'esc'],
BS: ['backspace', 'bs'],
Del: ['delete', 'del'],
' ': ['<space>'],
'\n': ['<cr>', '<enter>']
};

/**
* Normalizes key to AngleBracketNotation
* (e.g. <ctrl+x>, Ctrl+x, <c-x> normalized to <C-x>)
* and resolves special cases such as '<leader>'
* and converts the characters to their literals
* (e.g. <space>, <cr>, <leader>)
*/
public static NormalizeKey(key: string, leaderKey: string): string {
if (!this.isSurroundedByAngleBrackets(key) && key.length > 1) {
key = `<${key.toLocaleLowerCase()}>`;
}

// Special cases that we handle incorrectly (internally)
if (key.toLocaleLowerCase() === '<space>') {
return ' ';
}

if (key.toLocaleLowerCase() === '<cr>' || key.toLocaleLowerCase() === '<enter>') {
return '\n';
}

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

if (_.includes(['<up>', '<down>', '<left>', '<right>'], key.toLocaleLowerCase())) {
key = key.toLocaleLowerCase();
return key.toLocaleLowerCase();
}

for (const notationMapKey in this._notationMap) {
Expand Down

0 comments on commit 4b79f1a

Please sign in to comment.