<commit_before>var keyRegex = /^[a-h][1-8]$/;
var fileRegex = /^[a-h]$/;

lichess.keyboardMove = function(opts) {
  if (opts.input.classList.contains('ready')) return;
  opts.input.classList.add('ready');
  var writer = sanWriter();
  var sans = null;
  var submit = function(v, force) {
    var foundUci = v.length >= 2 && sans && sanToUci(v, sans);
    if (foundUci) {
      // ambiguous castle
      if (v.toLowerCase() === 'o-o' && sans['O-O-O'] && !force) return;
      // ambiguous UCI
      if (v.match(keyRegex) && opts.hasSelected()) opts.select(v);
      else opts.san(foundUci.slice(0, 2), foundUci.slice(2));
      clear();
    } else if (sans && v.match(keyRegex)) {
      opts.select(v);
      clear();
    } else if (sans && v.match(fileRegex)) {
      // do nothing
    } else
      opts.input.classList.toggle('wrong', v.length && sans && !sanCandidates(v, sans).length);
  };
  var clear = function() {
    opts.input.value = '';
    opts.input.classList.remove('wrong');
  };
  makeBindings(opts, submit, clear);
  return function(fen, dests) {
    sans = dests && Object.keys(dests).length ? writer(fen, destsToUcis(dests)) : null;
    submit(opts.input.value);
  };
}

function makeBindings(opts, submit, clear) {
  Mousetrap.bind('enter', function() {
    opts.input.focus();
  });
  opts.input.addEventListener('keyup', function(e) {
    var v = e.target.value;
    if (v.indexOf('/') > -1) {
      focusChat();
      clear();
    } else submit(v, e.keyCode === 13);
  });
  opts.input.addEventListener('focus', function() {
    opts.setFocus(true);
  });
  opts.input.addEventListener('blur', function() {
    opts.setFocus(false);
  });
}

function sanToUci(san, sans) {
  var lowered = san.toLowerCase();
  for (var i in sans)
    if (i.toLowerCase() === lowered) return sans[i];
}

function sanCandidates(san, sans) {
  var lowered = san.toLowerCase();
  return Object.keys(sans).filter(function(s) {
    return s.toLowerCase().indexOf(lowered) === 0;
  });
}

function destsToUcis(dests) {<commit_msg>Allow SAN moves to be case-sensitive or case-insensitive. Fix #3035<commit_after>var keyRegex = /^[<KEY>;
var fileRegex = /^[a-h]$/;

lichess.keyboardMove = function(opts) {
  if (opts.input.classList.contains('ready')) return;
  opts.input.classList.add('ready');
  var writer = sanWriter();
  var sans = null;
  var submit = function(v, force) {
    var foundUci = v.length >= 2 && sans && sanToUci(v, sans);
    if (foundUci) {
      // ambiguous castle
      if (v.toLowerCase() === 'o-o' && sans['O-O-O'] && !force) return;
      // ambiguous UCI
      if (v.match(keyRegex) && opts.hasSelected()) opts.select(v);
      else opts.san(foundUci.slice(0, 2), foundUci.slice(2));
      clear();
    } else if (sans && v.match(keyRegex)) {
      opts.select(v);
      clear();
    } else if (sans && v.match(fileRegex)) {
      // do nothing
    } else
      opts.input.classList.toggle('wrong', v.length && sans && !sanCandidates(v, sans).length);
  };
  var clear = function() {
    opts.input.value = '';
    opts.input.classList.remove('wrong');
  };
  makeBindings(opts, submit, clear);
  return function(fen, dests) {
    sans = dests && Object.keys(dests).length ? writer(fen, destsToUcis(dests)) : null;
    submit(opts.input.value);
  };
}

function makeBindings(opts, submit, clear) {
  Mousetrap.bind('enter', function() {
    opts.input.focus();
  });
  opts.input.addEventListener('keyup', function(e) {
    var v = e.target.value;
    if (v.indexOf('/') > -1) {
      focusChat();
      clear();
    } else submit(v, e.keyCode === 13);
  });
  opts.input.addEventListener('focus', function() {
    opts.setFocus(true);
  });
  opts.input.addEventListener('blur', function() {
    opts.setFocus(false);
  });
}

function sanToUci(san, sans) {
  for (var i in sans)
    if (i === san) return sans[i];
  var lowered = san.toLowerCase();
  for (var i in sans)
    if (i.toLowerCase() === lowered) return sans[i];
}

function sanCandidates(san, sans) {
  var lowered = san.toLowerCase();
  return Object.keys(sans).filter(function(s) {
    return s.toLowerCase().indexOf(lowered) === 0;
  });
}

function destsToUcis(dests) {
{'fraction_non_alphanumeric': 0.18616382416526545, 'fraction_numerical': 0.005284650492433342, 'mean_word_length': 3.270769230769231, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '6325505', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1460, 'n_words': 303}