| 301 | // Parses the user's keyMapping config text and persists the parsed key mappings into the |
| 302 | // extension's storage, for use by the other parts of this extension. |
| 303 | async loadKeyMappings(userKeyMappingsConfigText) { |
| 304 | let key, command; |
| 305 | this.keyToRegistryEntry = {}; |
| 306 | this.mapKeyRegistry = {}; |
| 307 | |
| 308 | const defaultKeyConfig = Object.keys(defaultKeyMappings).map((key) => |
| 309 | `map ${key} ${defaultKeyMappings[key]}` |
| 310 | ).join("\n"); |
| 311 | |
| 312 | const parsed = KeyMappingsParser.parse( |
| 313 | defaultKeyConfig + "\n" + userKeyMappingsConfigText, |
| 314 | true, |
| 315 | ); |
| 316 | this.mapKeyRegistry = parsed.keyToMappedKey; |
| 317 | this.keyToRegistryEntry = parsed.keyToRegistryEntry; |
| 318 | |
| 319 | await chrome.storage.session.set({ mapKeyRegistry: this.mapKeyRegistry }); |
| 320 | await this.installKeyStateMapping(); |
| 321 | this.prepareHelpPageData(); |
| 322 | |
| 323 | // Push the key mappings from any passNextKey commands into storage so that they're's available |
| 324 | // to the front end so they can be detected during insert mode. We exclude single-key mappings |
| 325 | // for this command (i.e. printable keys) because we're considering that a configuration error: |
| 326 | // when users press printable keys in insert mode, they expect that character to be input, not |
| 327 | // to be droppped into a special Vimium mode. |
| 328 | const passNextKeys = Object.entries(this.keyToRegistryEntry) |
| 329 | .filter(([key, v]) => v.command == "passNextKey" && key.length > 1) |
| 330 | .map(([key, v]) => key); |
| 331 | await chrome.storage.session.set({ passNextKeyKeys: passNextKeys }); |
| 332 | }, |
| 333 | |
| 334 | // This generates and installs a nested key-to-command mapping structure. There is an example in |
| 335 | // mode_key_handler.js. |