<commit_before>var availableCommands    = {};
var keyToCommandRegistry = {};

function addCommand(command, description, isBackgroundCommand) {
  if (availableCommands[command])
  {
    console.log(command, "is already defined! Check commands.js for duplicates.");
    return;
  }

  availableCommands[command] = { description: description, isBackgroundCommand: isBackgroundCommand };
}

function mapKeyToCommand(key, command) {
  if (!availableCommands[command])
  {
    console.log(command, "doesn't exist!");
    return;
  }

  keyToCommandRegistry[key] = { command: command, isBackgroundCommand: availableCommands[command].isBackgroundCommand };
}

function unmapKey(key) { delete keyToCommandRegistry[key]; }

/* Lower-case the appropriate portions of named keys.
 *
 * A key name is one of three forms exemplified by <c-a> <left> or <c-f12>
 * (prefixed normal key, named key, or prefixed named key). Internally, for
 * simplicity, we would like prefixes and key names to be lowercase, though
 * humans may prefer other forms <Left> or <C-a>.
 * On the other hand, <c-a> and <c-A> are different named keys - for one of
 * them you have to press "shift" as well.
 */
function normalizeKey(key) {
    return key.replace(/<[acm]-/ig, function(match){ return match.toLowerCase(); })
              .replace(/<([acm]-)?([a-zA-Z0-9]{2,5})>/g, function(match, optionalPrefix, keyName){
                  return "<" + ( optionalPrefix ? optionalPrefix : "") + keyName.toLowerCase() + ">";
              });
}

function parseCustomKeyMappings(customKeyMappings) {
  lines = customKeyMappings.split("\n");

  for (var i = 0; i < lines.length; i++) {
    if (lines[i][0] == "\"" || lines[i][0] == "#") { continue }
    split_line = lines[i].split(/\s+/);

    var lineCommand = split_line[0];

    if (lineCommand == "map") {
      if (split_line.length != 3) { continue; }
      var key = normalizeKey(split_line[1]);
      var vimiumCommand = split_line[2];

      if (!availableCommands[vimiumCommand]) { continue }

      console.log("Mapping", key, "to", vimiumCommand);
      mapKeyToCommand(key, vimiumCommand);
    }
    else if (lineCommand == "unmap") {
      if (split_line.length != 2) { continue; }

      var key = normalizeKey(split_line[1]);

      console.log("Unmapping", key);
      unmapKey(key);
    }
    else if (lineCommand == "unmapAll") {
      keyToCommandRegistry = {};
    }
  }
}

function clearKeyMappingsAndSetDefaults() {
  keyToCommandRegistry = {};

  mapKeyToCommand('?', 'showHelp');
  mapKeyToCommand('j', 'scrollDown');
  mapKeyToCommand('k', 'scrollUp');
  mapKeyToCommand('h', 'scrollLeft');
  mapKeyToCommand('l', 'scrollRight');

  mapKeyToCommand('gg', 'scrollToTop');
  mapKeyToCommand('G', 'scrollToBottom');
  mapKeyToCommand('ga', 'scrollToLeft');
  mapKeyToCommand('gd', 'scrollToRight');
  mapKeyToCommand('<c-e>', 'scrollDown');
  mapKeyToCommand('<c-y>', 'scrollUp');
  mapKeyToCommand('<c-d>', 'scrollPageDown');
  mapKeyToCommand('<c-u>', 'scrollPageUp');
  mapKeyToCommand('<c-f>', 'scrollFullPageDown');
  mapKeyToCommand('<c-b>', 'scrollFullPageUp');
  mapKeyToCommand('r', 'reload');
  mapKeyToCommand('gf', 'toggleViewSource');

  mapKeyToCommand('i', 'enterInsertMode');

  mapKeyToCommand('H', 'goBack');
  mapKeyToCommand('L', 'goForward');
  mapKeyToCommand('gu', 'goUp');

  mapKeyToCommand('zi', 'zoomIn');
  mapKeyToCommand('zo', 'zoomOut');<commit_msg>Change default keys for scrollToLeft and scrollToRight to be zH, zL respectively.<commit_after>var availableCommands    = {};
var keyToCommandRegistry = {};

function addCommand(command, description, isBackgroundCommand) {
  if (availableCommands[command])
  {
    console.log(command, "is already defined! Check commands.js for duplicates.");
    return;
  }

  availableCommands[command] = { description: description, isBackgroundCommand: isBackgroundCommand };
}

function mapKeyToCommand(key, command) {
  if (!availableCommands[command])
  {
    console.log(command, "doesn't exist!");
    return;
  }

  keyToCommandRegistry[key] = { command: command, isBackgroundCommand: availableCommands[command].isBackgroundCommand };
}

function unmapKey(key) { delete keyToCommandRegistry[key]; }

/* Lower-case the appropriate portions of named keys.
 *
 * A key name is one of three forms exemplified by <c-a> <left> or <c-f12>
 * (prefixed normal key, named key, or prefixed named key). Internally, for
 * simplicity, we would like prefixes and key names to be lowercase, though
 * humans may prefer other forms <Left> or <C-a>.
 * On the other hand, <c-a> and <c-A> are different named keys - for one of
 * them you have to press "shift" as well.
 */
function normalizeKey(key) {
    return key.replace(/<[acm]-/ig, function(match){ return match.toLowerCase(); })
              .replace(/<([acm]-)?([a-zA-Z0-9]{2,5})>/g, function(match, optionalPrefix, keyName){
                  return "<" + ( optionalPrefix ? optionalPrefix : "") + keyName.toLowerCase() + ">";
              });
}

function parseCustomKeyMappings(customKeyMappings) {
  lines = customKeyMappings.split("\n");

  for (var i = 0; i < lines.length; i++) {
    if (lines[i][0] == "\"" || lines[i][0] == "#") { continue }
    split_line = lines[i].split(/\s+/);

    var lineCommand = split_line[0];

    if (lineCommand == "map") {
      if (split_line.length != 3) { continue; }
      var key = normalizeKey(split_line[1]);
      var vimiumCommand = split_line[2];

      if (!availableCommands[vimiumCommand]) { continue }

      console.log("Mapping", key, "to", vimiumCommand);
      mapKeyToCommand(key, vimiumCommand);
    }
    else if (lineCommand == "unmap") {
      if (split_line.length != 2) { continue; }

      var key = normalizeKey(split_line[1]);

      console.log("Unmapping", key);
      unmapKey(key);
    }
    else if (lineCommand == "unmapAll") {
      keyToCommandRegistry = {};
    }
  }
}

function clearKeyMappingsAndSetDefaults() {
  keyToCommandRegistry = {};

  mapKeyToCommand('?', 'showHelp');
  mapKeyToCommand('j', 'scrollDown');
  mapKeyToCommand('k', 'scrollUp');
  mapKeyToCommand('h', 'scrollLeft');
  mapKeyToCommand('l', 'scrollRight');

  mapKeyToCommand('gg', 'scrollToTop');
  mapKeyToCommand('G', 'scrollToBottom');
  mapKeyToCommand('zH', 'scrollToLeft');
  mapKeyToCommand('zL', 'scrollToRight');
  mapKeyToCommand('<c-e>', 'scrollDown');
  mapKeyToCommand('<c-y>', 'scrollUp');
  mapKeyToCommand('<c-d>', 'scrollPageDown');
  mapKeyToCommand('<c-u>', 'scrollPageUp');
  mapKeyToCommand('<c-f>', 'scrollFullPageDown');
  mapKeyToCommand('<c-b>', 'scrollFullPageUp');
  mapKeyToCommand('r', 'reload');
  mapKeyToCommand('gf', 'toggleViewSource');

  mapKeyToCommand('i', 'enterInsertMode');

  mapKeyToCommand('H', 'goBack');
  mapKeyToCommand('L', 'goForward');
  mapKeyToCommand('gu', 'goUp');

  mapKeyToCommand('zi', 'zoomIn');
  mapKeyToCommand('zo', 'zoomOut');
{'fraction_non_alphanumeric': 0.1648287869994196, 'fraction_numerical': 0.004352872896111433, 'mean_word_length': 4.314572089437163, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3768483', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2190, 'n_words': 492}