-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #716. Remapper options should be case-insensitive
- Loading branch information
Showing
6 changed files
with
65 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class AngleBracketNotation { | ||
private static _notationMap : { [key:string] : string[]; } = { | ||
'C-': ['ctrl\\+', 'c\\-'], | ||
'Esc': ['escape', 'esc'], | ||
'BS': ['backspace', 'bs'], | ||
'Del': ['delete', 'del'], | ||
}; | ||
|
||
/** | ||
* Normalizes key to AngleBracketNotation | ||
* For instance, <ctrl+x>, Ctrl+x, <c-x> normalized to <C-x> | ||
*/ | ||
public static Normalize(key: string): string { | ||
if (!this.IsSurroundedByAngleBrackets(key) && key.length > 1) { | ||
key = `<${ key.toLocaleLowerCase() }>`; | ||
} | ||
|
||
for (const notationMapKey in this._notationMap) { | ||
if (this._notationMap.hasOwnProperty(notationMapKey)) { | ||
const regex = new RegExp(this._notationMap[notationMapKey].join('|'), 'gi'); | ||
if (regex.test(key)) { | ||
key = key.replace(regex, notationMapKey); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return key; | ||
} | ||
|
||
private static IsSurroundedByAngleBrackets(key: string): boolean { | ||
return key.startsWith('<') && key.endsWith('>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
|
||
import * as assert from 'assert'; | ||
import { AngleBracketNotation } from '../src/notation'; | ||
|
||
suite("Notation", () => { | ||
test("Normalize", () => { | ||
let testCases = { | ||
'<cTrL+w>': '<C-w>', | ||
'cTrL+x': '<C-x>', | ||
'CtRl+y': '<C-y>', | ||
'c-z': '<C-z>', | ||
}; | ||
|
||
for (const test in testCases) { | ||
if (testCases.hasOwnProperty(test)) { | ||
let expected = testCases[test]; | ||
|
||
let actual = AngleBracketNotation.Normalize(test); | ||
assert.equal(actual, expected); | ||
} | ||
} | ||
}); | ||
}); |