diff options
author | Shin'ya UEOKA <ueokande@i-beam.org> | 2019-10-04 04:01:35 +0000 |
---|---|---|
committer | Shin'ya UEOKA <ueokande@i-beam.org> | 2019-10-06 12:58:59 +0000 |
commit | 410ffbb0376b9399928ef8d4dd13079bfb120e14 (patch) | |
tree | e408870fb867c7affb04c9b0130463df24e9f097 /src/shared/Settings.ts | |
parent | b496cea5827165bd23a503231f94f708a976cad4 (diff) |
Make Keymap class
Diffstat (limited to 'src/shared/Settings.ts')
-rw-r--r-- | src/shared/Settings.ts | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/shared/Settings.ts b/src/shared/Settings.ts index d338e2a..3014abc 100644 --- a/src/shared/Settings.ts +++ b/src/shared/Settings.ts @@ -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: { |