Make Keymap class
This commit is contained in:
parent
b496cea582
commit
410ffbb037
15 changed files with 223 additions and 129 deletions
|
@ -1,7 +1,5 @@
|
|||
import * as operations from './operations';
|
||||
import * as PropertyDefs from './property-defs';
|
||||
|
||||
export type Keymaps = {[key: string]: operations.Operation};
|
||||
import Keymaps from './settings/Keymaps';
|
||||
|
||||
export interface Search {
|
||||
default: string;
|
||||
|
@ -21,14 +19,6 @@ export default interface Settings {
|
|||
blacklist: string[];
|
||||
}
|
||||
|
||||
export const keymapsValueOf = (o: any): Keymaps => {
|
||||
return Object.keys(o).reduce((keymaps: Keymaps, key: string): Keymaps => {
|
||||
let op = operations.valueOf(o[key]);
|
||||
keymaps[key] = op;
|
||||
return keymaps;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const searchValueOf = (o: any): Search => {
|
||||
if (typeof o.default !== 'string') {
|
||||
throw new TypeError('string field "default" not set"');
|
||||
|
@ -97,7 +87,7 @@ export const valueOf = (o: any): Settings => {
|
|||
for (let key of Object.keys(o)) {
|
||||
switch (key) {
|
||||
case 'keymaps':
|
||||
settings.keymaps = keymapsValueOf(o.keymaps);
|
||||
settings.keymaps = Keymaps.fromJSON(o.keymaps);
|
||||
break;
|
||||
case 'search':
|
||||
settings.search = searchValueOf(o.search);
|
||||
|
@ -115,8 +105,17 @@ export const valueOf = (o: any): Settings => {
|
|||
return settings;
|
||||
};
|
||||
|
||||
export const toJSON = (settings: Settings): any => {
|
||||
return {
|
||||
keymaps: settings.keymaps.toJSON(),
|
||||
search: settings.search,
|
||||
properties: settings.properties,
|
||||
blacklist: settings.blacklist,
|
||||
};
|
||||
};
|
||||
|
||||
export const DefaultSetting: Settings = {
|
||||
keymaps: {
|
||||
keymaps: Keymaps.fromJSON({
|
||||
'0': { 'type': 'scroll.home' },
|
||||
':': { 'type': 'command.show' },
|
||||
'o': { 'type': 'command.show.open', 'alter': false },
|
||||
|
@ -179,7 +178,7 @@ export const DefaultSetting: Settings = {
|
|||
'N': { 'type': 'find.prev' },
|
||||
'.': { 'type': 'repeat.last' },
|
||||
'<S-Esc>': { 'type': 'addon.toggle.enabled' }
|
||||
},
|
||||
}),
|
||||
search: {
|
||||
default: 'google',
|
||||
engines: {
|
||||
|
|
Reference in a new issue