<commit_before>(function() {

  var TIME_INTERVAL = Math.ceil(1000/24);
  var BACKSPACE_KEY = 8;
  var ENTER_KEY = 13;
  var NUM0_KEY = 0x30;
  var NUM9_KEY = 0x39;
  var TOO_MUCH_INSPECTION = 17000;

  function TimerController() {
    this._stackmat = new window.app.Stackmat();

    this._inputMode = 0;
    this._interval = null;
    this._intervalStartTime = null;
    this._inputModeChanged = true;

    this._updateInputMode();
    this._registerModelEvents();
    this._registerStackmatEvents();
    this._registerUIEvents();
  }

  TimerController.prototype.keydown = function(e) {
    // Forward backspace to this.keypress().
    if (this._inputMode === window.app.Timer.INPUT_ENTRY &&
        e.which === BACKSPACE_KEY) {
      return this.keypress(e);
    }
    return true;
  };

  TimerController.prototype.keypress = function(e) {
    if (this._inputMode !== window.app.Timer.INPUT_ENTRY) {
      return true;
    }

    if (e.which === BACKSPACE_KEY) {
      var oldTime = window.app.timer.getManualTime();
      window.app.timer.setManualTime(oldTime.substring(0, oldTime.length-1));
    } else if (e.which >= NUM0_KEY && e.which <= NUM9_KEY) {
      var oldTime = window.app.timer.getManualTime();
      // Typing leading zeroes is pointless, so I ignore them.
      if ((oldTime.length !== 0 || e.which !== NUM0_KEY) &&
          oldTime.length < 7) {
        window.app.timer.setManualTime(oldTime + (e.which - 0x30));
      }
    } else if (e.which === ENTER_KEY) {
      if (window.app.timer.getManualTime().length > 0) {
        window.app.timer.saveTime();
        window.app.timer.reset();
      }
    } else {
      // Unknown keys should be propagated.
      return true;
    }

    return false;
  };

  TimerController.prototype.keyup = function(e) {
    // Allow the event to propagate.
    return true;
  };

  TimerController.prototype._controlCancel = function() {
    if (window.app.timer.getState() === window.app.Timer.STATE_NOT_RUNNING) {
      return;
    }
    this._stopInterval();
    window.app.timer.reset();
    this._updateInputMode();
  };

  TimerController.prototype._controlDown = function() {
    switch (window.app.timer.getState()) {
    case window.app.Timer.STATE_NOT_RUNNING:
      if (this._inputMode === window.app.Timer.INPUT_INSPECTION) {
        window.app.timer.phaseInspectionReady();
      } else {
        window.app.timer.phaseReady();
      }
      break;
    case window.app.Timer.STATE_INSPECTION:
      // NOTE: inspection keeps running until they release the spacebar or
      // lift their finger.
      break;
    case window.app.Timer.STATE_TIMING:
      window.app.timer.setTime(this._elapsedTime());
      if (this._inputMode === window.app.Timer.INPUT_BLD &&
          !window.app.timer.hasMemoTime()) {
        window.app.timer.doneMemo();
      } else {
        window.app.timer.phaseDone();
        this._stopInterval();
      }
      break;
    default:
      throw new Error('unexpected state: ' + window.app.timer.getState());
    }
  };

  TimerController.prototype._controlUp = function() {
    switch (window.app.timer.getState()) {
    case window.app.Timer.STATE_INSPECTION_READY:
      window.app.timer.phaseInspection();
      this._startInterval();
      break;
    case window.app.Timer.STATE_INSPECTION:
      window.app.timer.setInspectionTime(this._elapsedTime());
      this._stopInterval();
    case window.app.Timer.STATE_READY:
      window.app.timer.phaseTiming();
      this._startInterval();
      break;
    case window.app.Timer.STATE_DONE:
      window.app.timer.saveTime();
      window.app.timer.reset();
      break;
    case window.app.Timer.STATE_TIMING:
      // NOTE: this will occur if they just finished recording the memo time and
      // are now lifting their finger or releasing the spacebar.
      // This may also occur if they press space or touch the screen while
      // inspection is running, then don't release until inspection goes over
      // and forces the timer to start.
      break;
    default:
      throw new Error('unexpected state: ' + window.app.timer.getState());
    }
  };<commit_msg>temporarily disable timer after done timing<commit_after>(function() {

  var TIME_INTERVAL = Math.ceil(1000/24);
  var BACKSPACE_KEY = 8;
  var ENTER_KEY = 13;
  var NUM0_KEY = 0x30;
  var NUM9_KEY = 0x39;
  var TOO_MUCH_INSPECTION = 17000;
  var TEMP_DISABLE_TIMEOUT = 100;

  function TimerController() {
    this._stackmat = new window.app.Stackmat();

    this._inputMode = 0;
    this._interval = null;
    this._intervalStartTime = null;
    this._inputModeChanged = true;
    this._temporarilyDisabled = false;

    this._updateInputMode();
    this._registerModelEvents();
    this._registerStackmatEvents();
    this._registerUIEvents();
  }

  TimerController.prototype.keydown = function(e) {
    // Forward backspace to this.keypress().
    if (this._inputMode === window.app.Timer.INPUT_ENTRY &&
        e.which === BACKSPACE_KEY) {
      return this.keypress(e);
    }
    return true;
  };

  TimerController.prototype.keypress = function(e) {
    if (this._inputMode !== window.app.Timer.INPUT_ENTRY) {
      return true;
    }

    if (e.which === BACKSPACE_KEY) {
      var oldTime = window.app.timer.getManualTime();
      window.app.timer.setManualTime(oldTime.substring(0, oldTime.length-1));
    } else if (e.which >= NUM0_KEY && e.which <= NUM9_KEY) {
      var oldTime = window.app.timer.getManualTime();
      // Typing leading zeroes is pointless, so I ignore them.
      if ((oldTime.length !== 0 || e.which !== NUM0_KEY) &&
          oldTime.length < 7) {
        window.app.timer.setManualTime(oldTime + (e.which - 0x30));
      }
    } else if (e.which === ENTER_KEY) {
      if (window.app.timer.getManualTime().length > 0) {
        window.app.timer.saveTime();
        window.app.timer.reset();
      }
    } else {
      // Unknown keys should be propagated.
      return true;
    }

    return false;
  };

  TimerController.prototype.keyup = function(e) {
    // Allow the event to propagate.
    return true;
  };

  TimerController.prototype._controlCancel = function() {
    if (window.app.timer.getState() === window.app.Timer.STATE_NOT_RUNNING) {
      return;
    }
    this._stopInterval();
    window.app.timer.reset();
    this._updateInputMode();
  };

  TimerController.prototype._controlDown = function() {
    if (this._temporarilyDisabled) {
      return;
    }

    switch (window.app.timer.getState()) {
    case window.app.Timer.STATE_NOT_RUNNING:
      if (this._inputMode === window.app.Timer.INPUT_INSPECTION) {
        window.app.timer.phaseInspectionReady();
      } else {
        window.app.timer.phaseReady();
      }
      break;
    case window.app.Timer.STATE_INSPECTION:
      // NOTE: inspection keeps running until they release the spacebar or
      // lift their finger.
      break;
    case window.app.Timer.STATE_TIMING:
      window.app.timer.setTime(this._elapsedTime());
      if (this._inputMode === window.app.Timer.INPUT_BLD &&
          !window.app.timer.hasMemoTime()) {
        window.app.timer.doneMemo();
      } else {
        window.app.timer.phaseDone();
        this._stopInterval();
      }
      break;
    default:
      throw new Error('unexpected state: ' + window.app.timer.getState());
    }
  };

  TimerController.prototype._controlUp = function() {
    switch (window.app.timer.getState()) {
    case window.app.Timer.STATE_INSPECTION_READY:
      window.app.timer.phaseInspection();
      this._startInterval();
      break;
    case window.app.Timer.STATE_INSPECTION:
      window.app.timer.setInspectionTime(this._elapsedTime());
      this._stopInterval();
    case window.app.Timer.STATE_READY:
      window.app.timer.phaseTiming();
      this._startInterval();
      break;
    case window.app.Timer.STATE_DONE:
      window.app.timer.saveTime();
      window.app.timer.reset();
      this._temporarilyDisabled = true;
      setTimeout(function() {
        this._temporarilyDisabled = false;
      }.bind(this), TEMP_DISABLE_TIMEOUT);
      break;
    case window.app.Timer.STATE_TIMING:
      // NOTE: this will occur if they just finished recording the memo time and
      // are now lifting their finger or releasing the spacebar.
      // This may also occur if they press space or touch the screen while
      // inspection is running, then don't release until inspection goes over
      // and forces the timer to start.
      break;
    case window.app.Timer.STATE_NOT_RUNNING:
      // NOTE: this may occur if this._temporarilyDisabled was set in
      // this._controlDown.
      break;
    default:
      throw new Error('unexpected state: ' + window.app.timer.getState());
    }
  };
{'fraction_non_alphanumeric': 0.12461309182620658, 'fraction_numerical': 0.008139401582024534, 'mean_word_length': 2.657861635220126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2744099', 'n_tokens_mistral': 2788, 'n_tokens_neox': 2690, 'n_words': 555}