-
-
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.
map keys from US keyboard to other layouts
- Loading branch information
1 parent
9db9fa3
commit b4ead66
Showing
6 changed files
with
134 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {KeyboardLayout} from "./keyboard"; | ||
|
||
export default class Configuration { | ||
|
||
keyboardLayout : KeyboardLayout; | ||
|
||
constructor(keyboard : KeyboardLayout) { | ||
this.keyboardLayout = keyboard; | ||
} | ||
|
||
static fromUserFile() { | ||
// TODO: read .vimrc or a similar file. | ||
return new Configuration(KeyboardLayout.fromUserConfiguration()); | ||
} | ||
} |
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,58 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export class KeyboardLayout { | ||
private mapper : KeyMapper; | ||
|
||
constructor(mapper? : KeyMapper) { | ||
this.mapper = mapper; | ||
} | ||
|
||
get name() : string { | ||
return this.mapper ? this.mapper.name : "en-US (QWERTY)"; | ||
} | ||
|
||
resolve (key : string) : string { | ||
return this.mapper ? this.mapper.resolve(key) : key; | ||
} | ||
|
||
static fromUserConfiguration() : KeyboardLayout { | ||
const layout = vscode.workspace.getConfiguration('vim').get("keyboardLayout"); | ||
|
||
console.log("Using Vim keyboard layout: " + layout); | ||
|
||
switch (layout) { | ||
case 'es-ES (QWERTY)': | ||
return new KeyboardLayout(new KeyMapperEsEsQwerty()); | ||
|
||
default: | ||
return new KeyboardLayout(); | ||
} | ||
} | ||
} | ||
|
||
export interface KeyMapper { | ||
name : string; | ||
resolve(key : string) : string; | ||
} | ||
|
||
class KeyMapperEsEsQwerty implements KeyMapper { | ||
|
||
private mappings = {}; | ||
|
||
constructor() { | ||
this.mappings = { | ||
'>': ':', | ||
// '\\': '<', // doesn't really work; in my keyboard there are two keys for \ in US | ||
';': 'ñ', | ||
"'": "´" | ||
}; | ||
} | ||
|
||
get name() : string { | ||
return 'es-ES'; | ||
} | ||
|
||
resolve(key : string) : string { | ||
return this.mappings[key] || key; | ||
} | ||
} |
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,40 @@ | ||
// The module 'assert' provides assertion methods from node | ||
import * as assert from 'assert'; | ||
import {KeyboardLayout, KeyMapper} from '../src/keyboard'; | ||
|
||
suite("KeyboardLayout", () => { | ||
|
||
test("ctor", () => { | ||
const layout = new KeyboardLayout(); | ||
assert.equal(layout.name, "en-US (QWERTY)"); | ||
}); | ||
|
||
test("lets keys through if using default layout", () => { | ||
const layout = new KeyboardLayout(); | ||
assert.equal(layout.resolve('>'), '>'); | ||
assert.equal(layout.resolve(':'), ':'); | ||
assert.equal(layout.resolve('.'), '.'); | ||
}); | ||
|
||
test("can use custom mapper", () => { | ||
class FakeMapper implements KeyMapper { | ||
get name() : string { | ||
return "fake mapper"; | ||
} | ||
|
||
resolve(key : string) : string { | ||
return "fake key"; | ||
} | ||
} | ||
|
||
const layout = new KeyboardLayout(new FakeMapper()); | ||
assert.equal(layout.name, "fake mapper"); | ||
assert.equal(layout.resolve('>'), 'fake key'); | ||
assert.equal(layout.resolve(':'), 'fake key'); | ||
assert.equal(layout.resolve('.'), 'fake key'); | ||
}); | ||
}); | ||
|
||
suite("KeyMapperEsEsQwerty", () => { | ||
// TODO: cannot set settings from api? | ||
}); |