MCPcopy
hub / github.com/philc/vimium / prepareHelpPageData

Function prepareHelpPageData

background_scripts/commands.js:370–406  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

368 // Build the "commandToOptionsToKeys" data structure and place it in chrome's session storage.
369 // This is used by the help page and commands listing.
370 prepareHelpPageData() {
371 /*
372 Map of commands to option sets to keys to trigger that command option set.
373 Commands with no options will have the empty string options set.
374 Example:
375 {
376 "zoomReset": {
377 "": ["z0", "zz"] // No options, with two key maps, ie: `map zz zoomReset`
378 },
379 "setZoom": {
380 "1.1": ["z1"], // `map z1 setZoom 1.1`
381 "1.2": ["z2"], // `map z2 setZoom 1.2`
382 }
383 }
384 */
385 const commandToOptionsToKeys = {};
386 const formatOptionString = (options) => {
387 return Object.entries(options)
388 .map(([k, v]) => {
389 // When the value of an option is true, then it was parsed as a flag.
390 if (v === true) {
391 return k;
392 } else {
393 return `${k}=${v}`;
394 }
395 })
396 .join(" ");
397 };
398 for (const key of Object.keys(this.keyToRegistryEntry || {})) {
399 const registryEntry = this.keyToRegistryEntry[key];
400 const optionString = formatOptionString(registryEntry.options || {});
401 commandToOptionsToKeys[registryEntry.command] ||= {};
402 commandToOptionsToKeys[registryEntry.command][optionString] ||= [];
403 commandToOptionsToKeys[registryEntry.command][optionString].push(key);
404 }
405 chrome.storage.session.set({ commandToOptionsToKeys });
406 },
407};
408
409const defaultKeyMappings = {

Callers

nothing calls this directly

Calls 3

formatOptionStringFunction · 0.85
setMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected